This talk has been presented at React Summit 2023, check out the latest edition of this React Conference.
Video: React Myths And Legends
FAQ
Nadia's main focus in her investigations for front-end developers is React Performance.
Mounting is the first time a component appears on the screen. This is when React initializes and wires everything together, firing all callbacks and use effects for the first time.
Context can help manage re-renders in React by allowing data to be passed directly to the components that need it, bypassing the rest of the component tree. This reduces the number of components that need to re-render, improving performance.
Common misconceptions about the key attribute in React include the belief that it prevents re-renders. The key attribute is used to help React identify which items have changed, been added, or removed, but it does not prevent re-renders.
Array indices should not be used as keys in React because they can lead to performance issues and bugs. When items are added or removed, using indices can cause unnecessary re-renders of all items in the list. It's better to use unique IDs.
When state changes in React, the parent component re-renders, and React propagates this update to its children recursively. This means all direct children and their children will re-render unless explicitly prevented.
Splitting context providers can help with re-renders in React by separating the state data and the functions into different contexts. This way, only the components that depend on the specific context will re-render when it changes, improving performance.
The 'Big Re-renders Myth' in React is the belief that a component re-renders when its props change. This is not true; re-renders are primarily caused by state changes.
Memoizing a component in React is important because it prevents unnecessary re-renders. Wrapping a component in React.memo ensures that React checks its props and only re-renders if the props have changed, improving performance.
Unnecessary re-renders in React can be caused by re-rendering the entire app or large parts of it when only a small component or piece of data has changed. This can lead to performance issues and slow interactions.