facebookexperimental / Recoil

Recoil is an experimental state management library for React apps. It provides several capabilities that are difficult to achieve with React alone, while being compatible with the newest features of React.
https://recoiljs.org/
MIT License
19.59k stars 1.19k forks source link

can Recoil stop update React Component update when atom value still same after update? #493

Closed xuzhanhh closed 4 years ago

xuzhanhh commented 4 years ago

Hey guys! I want to stop rerender Component when atom/selector get the same value after updater. What should I do?

Here's the playground: https://codesandbox.io/s/stoic-resonance-vecxs?file=/src/App.js:758-811

actually, I try to normalize todoState in a atom(todoIdListState) and atomFamily(todoState) mapping in order to avoid updating all <TodoItem/>, but when I add a state filteredTodoIdListState whitch subscribe atomFamily(todoState), it will cause rerender <TodoList/> when I changing one todoState atom. How can I stop this rerender? Is there a way like react useState's internal compare check? Here's the playground with normalize todo: https://codesandbox.io/s/condescending-sinoussi-d3ck0?file=/src/App.js:1853-1861

brianc commented 4 years ago

It looks like this commit might address that.

drarmstr commented 4 years ago

Setting atoms is addressed with #386, limiting re-renders of selectors with the same value is duplicate of #314

xuzhanhh commented 4 years ago

thanks!