8 ms·
Isn't `useContext` the builtin React alternative to that issue?
by fabioz 1y ago
Isn't `useContext` the builtin React alternative to that issue?
- Already__Taken 1y agoYes but they will rerender from where the context was created not where it's used, so you can get a lot of UI renders. I think the new memo compiler address' this in the most complicated way possible.
- owebmaster 1y ago> Yes but they will rerender from where the context was created Wow that's really bad and make it basically useless.
- jgalt212 1y agonot if the compiler stops the unneeded re-renders.
- owebmaster 1y agoA "compiler" to solve the issues the library created, awesome. It doesn't solve many re-renders tho, as React re-render full components, not only the HTML/Text Nodes that changed.
- Capricorn2481 1y agoA re-render in React is not as heavy as you'd think it is. It's painting the DOM that takes resources, and people conflate the two. But if your whole component re-renders because of a change in context, yet nothing on the page changed, you will likely not notice the render even on low-end devices. I still think Zustand is the simplest state management, while staying efficient. It's similar to the old Svelte stores. But I have used many state management tools and the re-renders were not the problem when it came to speed.
- SebastianKra 1y agoThat's simply not true. function MyProvider({ children }) { const [value, setValue] = useState() return <Context.Provider value={value}> {children} </Context.Provider> } In the above example, the Provider re-renders, but it's children remain unchanged.