I am working on a client-side application using React and Firebase. This week, I paired with another team member to add a new feature allowing user...
For further actions, you may consider blocking this person and/or reporting abuse
This is where memoization is useful. Memoization is the concept of keeping memory of a function return value to avoid repeated calls to functions that process the same input.
react.dev/reference/react/useMemo
On the initial render, useMemo returns the result of calling the callback. During next renders, it will either return an already stored value from the last render if the dependencies havenβt changed, or call the callback again and return the result.
Be aware that proper structure of component architecture would have got you to handle that logic from the parent component instead.
Since you already have a parent component passing "data" down to your Home component, you can also pass an "onSubmit" function as a prop that you add to the form element, and remove all the internal state from Home.
The parent component handles managing the state, including updating the list and displaying a success message, and the child becomes a "dumb" component whose sole responsibility is displaying whatever data it is given.
Totally agree here !
Great article! π₯