4 ms·
States are scoped to a component, how "every" component that get the prop update ?
by dezmou 3y ago
States 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.