Vad används useEffect() för?
Skapa side effects i en komponent.
useState()
Funktion för att använda state.
Where to put state?
As close as possible to the component/s using that state.
What prop do list items need in react?
key (with a unique ID for every item)
How to use react fragments?
Wrap siblings in <> </> in jsx
Vilka parametrar har useEffect?
Två parametrar:
- En funktion att exekvera,
- En array med variabler som om de ändras ska trigga funktionen i första parametern.
Vilka varianter finns för andra parametern i useEffect?
What does useState return?
en array med två värden:
State
Och setState
How to call useState?
const [state, setState] = useState(initialState);
Whats the html attribute “class” called in jsx?
className
What’s the label element’s attribute “for” called in jsx?
htmlFor
How to make a controlled input?
Pass a value prop with whatever state value you want the input to be. Use a handleChange to set state.
How to create a react component?
Write a JS-function that returns markup
How to nest react components?
Call a function that returns markup within another. Like this:
<Parent> <Child/> <Parent/>
How to add markup in react components?
JSX
How to add styles to react components?
How to display data in react components
Curly braces in JSX ‘escapes’ back in to js to interpolate variables or expressions.
How to render things conditionally?
Ternary operator if simple condition. Can be used in jsx because it’s an expression. Complex conditions are put in js and referenced from jsx with an expression.
What do lists in react need?
‘Key’ attribute with a unique value. React uses it to understand what is updated between renders.
How to respond to events in react?
Declare event handler functions in components. Pass them to Components listening for events.
How to update the screen in response to events in react?
Have your event handler functions set state and components will rerender i.e. update the screen.
How to share data between components in three steps?
How to pass a function with arguments as a callback?
Wrap it in an arrow function.
'onclick' = () => myFunction(arg)
The five steps of implementing a UI in react?