Posts

Showing posts with the label Usememo react native

How to Optimize React Performance with useMemo

Image
How to Optimize React Performance with useMemo Brief on how useMemo works A memoized value is returned by the useMemo Hook in React. Memoization is similar to saving a value from being recalculated by caching it. The only time the useMemo Hook runs is when one of its dependencies changes. This can help us to improve it's performance  Usememo syntax useMemo(calculateValue, dependencies) How to improve Performance by using  useMemo Using the useMemo Hook, you can stop expensive, resource-intensive functions from running all the time. We have an expensive function that runs on every render in this example. There will be a delay in execution when you change the count or add a to-do. A function that performs poorly. Every render calls the expensiveOperation function: import { useState } from "react"; import ReactDOM from "react-dom/client"; const App = () => {   const [count, setCount] = useState(0);   const [todos, setTodos] = useState([]);   const calculat...