Medium
const SomeComponent=({onChange, id})=>{
const handleClick= useCallback(()=>{
onChange(id);
},[]);
return <button onClick={()=>handleClick()}>Click me!</button>;
};
What are the issues with this code?
Author: Clément DEVOSStatus: PublishedQuestion passed 4655 times
Edit
8
Community Evaluations
Auteur anonyme
30/04/2024
Why is
"You must absolutely encapsulate the onClick handler in a useCallback, otherwise performance will be impacted"
the wrong answer?
the button with onClick={()=>handleClick()} will rerender whenever the parent component does, even if handleClick is wrapped in useCallback, we need to write this way onClick={handleClick} to avoid extra rerenders and a negative impact for performance
14
Save the state used to display the selected page in a React component.10
Write a React component that displays the sum of two numbers16
Write a React component as a function18
Call a function on the first render of a React component25
Write the missing code to render the children of the UserProfile component.10
Write a React component that updates the document title with each click and resets to 'React App' when the component unmounts.31
Write the non-JSX equivalent of the following code: