4 ms·
React is not reactive at all, the "state" management is you calling a function "setState" to re-render the component. And I find manual render very usefull and
by dezmou 3y ago
React is not reactive at all, the "state" management is you calling a function "setState" to re-render the component.
And I find manual render very usefull and once you do it, you can have a global state as simple as a global object, no need to use useState anymore.
https://github.com/dezmou/useRender https://github.com/dezmou/useRender
- boringuser2 3y agoThis is extremely inadvisable for numerous reasons and goes against the entire design philosophy of React. In short, injecting a naive render function over the react virtual dom calculation is wildly inefficient.
- dezmou 3y agoThis piece of code only rerender the component as if you do a setState, in fact it does a setState under the hood, maybe the word "render" is missleading.
- Capricorn2481 3y agoThe reactive part is every component getting that prop will update versus needing to write a function in jQuery to manually update the inner HTML of those components
- dezmou 3y agoStates are scoped to a component, how "every" component that get the prop update ?
- Capricorn2481 3y agoIf you pass a prop to a child component, it will update whenever you change state If two unrelated components are consuming the same context, it will update when that context updates. Using Zustand, there's virtually no overhead to this and it's extremely reactive
- dezmou 3y ago"If you pass a prop to a child component, it will update whenever you change state" Well if you update a state, every children of your component is updated as well regardless of if they have a prop passed. I know there are way to make react trully reactive like Valtio using proxy or maybe Zustand, but my point is that useState or useContext is not "reactive" at all, you must call a function to rerender the components.
- Capricorn2481 3y agoIf by "Updated" you mean they are looked at in the virtual DOM to determine if they have to update, then yes. But children aren't repainted onto the DOM just because their parent is. This still is Reactive
- dezmou 3y agoBy Updated I mean that more than comparing virtual DOM to real DOM. - If you have a useEffect without dependendy, it trigger it. - If you have some map, filter, sort, any lambda in your template, it will be executed again. And that is true for your component and every children recursively.