You're creating a new function for every input you manage for every render pass. This is an anti pattern especially on big state trees. Especially because it will cause re-renders of child components unnecessarily (as the onChange prop for each element changes every render pass. You may want to cache the created functions, or take a different approach
Passionate with code... In love with Web Design, Videogames, Books and Jazz music.Years of experience in "document composition" and a Front-End Developer wannabe (since years)
Passionate with code... In love with Web Design, Videogames, Books and Jazz music.Years of experience in "document composition" and a Front-End Developer wannabe (since years)
No worries, just wanted to chip in. Somehow dont see a note about rerender, I'm on mobile, perhaps some caching going on.
I like the alternative via name prop for input elements, or a custom data prop, as I wrote in the other comment thread.
Alternatively, I would still create a function property per onChange handler, but create and use a reusable function to limit the repetitiveness to the bare minimum.
You're creating a new function for every input you manage for every render pass. This is an anti pattern especially on big state trees. Especially because it will cause re-renders of child components unnecessarily (as the onChange prop for each element changes every render pass. You may want to cache the created functions, or take a different approach
But.. have you seen all the post? _^
I think so, what specifically did I overlook? Supplying a better alternative?
There’s a warning about rerendering... and me asking for suggestions ✌🏻
Sorry if it’s not perfect, I’m here for learning too.
No worries, just wanted to chip in. Somehow dont see a note about rerender, I'm on mobile, perhaps some caching going on.
I like the alternative via name prop for input elements, or a custom data prop, as I wrote in the other comment thread.
Alternatively, I would still create a function property per onChange handler, but create and use a reusable function to limit the repetitiveness to the bare minimum.
You can create a curried function and then memoize it. 😉 It should work! Have a look at Lodash's
curry
andmemoize
functions.