Answer the question
In order to leave comments, you need to log in
Performance React Hooks?
1. How does the functional structure and re-creation of handler functions affect memory and performance in React WEB and React Native?
const SomeButton = () => {
const [count, setCount] = useState(0);
return <Button onClick = {() => setCount(count + 1)}/>
}
Answer the question
In order to leave comments, you need to log in
1. It is clear that the creation of additional functions takes additional time. You will hardly notice the difference in the case of handlers.
2. It all depends on a number of circumstances. If you have nothing to do, then you can try writing benchmarks for different cases. For rendering a list of 1000 simple elements, it will not even be possible to fix the exact difference, since the timers work with a small error, and the count here goes to thousandths of a second and their fractions.
3. Even if you use the useCallback function, the function will still be re-created every render, moreover, when using useCallback, there will be a few additional internal calls. But the example from point 1, if the Button is a functional component, then this is exactly the case when useCallback, it seems, should be used, since it prevents the call of the theoretically more expensive operation - redrawing the Button.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question