Chapter 3: Writing Your First Application with React Hooks
What is the best practice for folder structures in React?
Start with a simple structure at first and nest more deeply when needed. Do not spend too much time thinking about the file structure when starting a project.
Which principle should we use when splitting up React components?
The single responsibility principle, which states that every component should have responsibility over a single encapsulated part of the functionality
What does themapfunction do?
The map function applies a given function to all elements of an array and returns a new array with the results
How does destructuring work, and when do we use it?
With destructuring, we can get properties from an object or elements from an array by specifying the structure and variable names on the left side of the assignment. We can use destructuring to get certain props in React components.
How does the spread operator work, and when do we use it?
The spread operator inserts all properties of an object or all elements of an array at a certain point in another object/array. It can be used to create new arrays or objects or to pass on all properties of an object as props to a React component.
How do we deal with input fields using React Hooks?
We create a State Hook for the input field value and define a handler function that sets the value
Where should local State Hooks be defined?
Local State Hooks should always be defined in the component where they are used
What is global state?
Global state is state that is used across multiple components throughout the whole application
Where should global State Hooks be defined?
Global State Hooks should be defined as high up in the component tree as possible. In our case, we defined them in the App component.