4IT580: Docs
4IT580 WebGithub

2nd Theoretical Class:
React cheatsheet

React

JSX

Allows us to write HTML code in React (JavaScript code) - mix JavaScript with HTML.

What is component?

It is function!

Custom components start everytime with capital letter!

Props

Special props

JavaScript in JSX

In JSX returned from function (component), we can use JavaSript properties, functions, etc. Pass JavaScript code into {} in JSX template.

Events

Execute JavaScript code (function, ...), when user interacts with application:

Hooks

Write function components

Side effects

Something will be changed from outside - API call.

useState

Hook which allows us to write state components.

Component lifecycle

useEffect

Allows us to controll all component lifecycle parts - mount, update and unmout - "If something happened, do something with component like fetch data, do a cleanup, etc.".

Execute side effect

When component is mounting, we need to fetch data.

Modern JavaScript

Import & Export

We have 2 types of exports.

Named exports

Default exports

var vs const & let

Don't use var! Use let only if neccesary! => Use const!

Template string

We have several ways how to work with strings

Destructuring