React is breaking code apart into pieces called…
components
What are the 5 steps of Thinking in React?
Break the UI in to a component hierarchy. What are the three different ways to do so?
Find the minimal but complete representation of UI state. What questions would you ask?
What’s left is probably state.
What is a component in React?
Piece of reusable code that represents a part of a user interface
export default function Square() {}
What does ‘export’ and ‘default’ mean?
export means that this function can be accessible form other files as well.
default means that this function is the main function in that file
React components need to return a single JSX element. If you have for example three different components, what do you do?
You wrap them inside <div></div> or <></>
React provides a special function called useState. What can you do with it?
you can call from your component to let it “remember” things
What are props?
Props are information that you pass to a JSX tag
How do you tell difference between React component and HTML tags?
React components start with the capital letter whilst HTML is lowercase
In what do you wrap around JS variable so you could use it in JSX?
Curly braces {}
style={{}} is not special syntax in JSX. What is it?
It is an object inside JSX curly braces
What JS features do you usually rely on when you want to render lists in React?
For loop or map() function
If you have a list of items in React, what should you give each and every item?
Key attribute. It gives each element an unique identification which helps to find that items among its siblings
In React where should the key attribute come from?
It should be coming from your data, such as database ID
In React what shall you do if you want your components to remember some information and display it?
useState
const [count, setCount] = useState(0);
Explain this.
You’ll get two things from useState, first parameter which is the current state and second parameter which allows you to change the current state. Right now the state is 0 because that’s what we passed there.
But if we want to change the count, we use setCount for that
Syntax is array destructing
In React what are called Hooks?
Functions starting with use. For example useState is a built-in hook
In React how can you change data between components? (for example you want buttons to update the count together whenever anyone has pressed one of the buttons)
You put useState on top of the closest component which contains the buttons
What is markup? Name some markup languages
Set of tags assigned to elements which declare how elements should be displayed or how they relate to one another. JSX, HTML, XML
React components are regular JavaScript functions except: (2)
Why is React good in that sense that without it CSS, HTML and JS would all be in different files
It helps you put logic, rendering and markup in the same file so everything that considers for example a Button is all found in one place. And it helps to also isolate details that are unrelated (so that you wouldn’t have button and navbar markup in the same file or sth like that)
What are the rules of JSX? (3)
Where to use curly braces in JSX? (2)