Advanced React Concepts Flashcards
What is context in React?
Context provides a way to pass data through the component tree without having to pass props down manually at every level.
How does React’s Concurrent Mode enhance user interfaces?
It allows React to interrupt a long-running render to handle high-priority events like user input, leading to more responsive apps.
What is a higher-order component (HOC)?
A HOC is a function that takes a component and returns a new component with added props or functionality.
Explain the purpose of the React.memo() function.
It memoizes the rendered output of a component, preventing unnecessary renders if props don’t change.
What is the purpose of useState in React?
To manage local state within a functional component.
When should you use useEffect?
When you want to perform side effects (like fetching data, manual DOM manipulations, etc.) in functional components.
What is useContext used for?
To access the context for a component without wrapping it in a Consumer.
When is it beneficial to use useReducer?
When state logic is more complex and involves multiple sub-values, or when the next state depends on the previous state.
What is the main purpose of useCallback?
To memoize functions so they don’t get recreated every render, especially when passed to child components as props to prevent unnecessary renders.
Why would you use useMemo?
To memoize expensive computations so they are only re-computed when specific inputs change.
When should you use useRef?
For accessing and interacting with DOM elements directly, or for keeping a mutable reference to a value that doesn’t trigger a re-render when it changes.
What does useImperativeHandle do?
It customizes the instance value that is exposed when using React.forwardRef.
When is useLayoutEffect used?
When you need to perform synchronous visual DOM updates, similar to useEffect but it fires synchronously after all DOM mutations.
What is useDebugValue used for?
It’s used in custom hooks to display a label in React DevTools next to this hook.
What is React’s context?
A mechanism for passing data directly to nested components without prop-drilling, often used for global state or theming.