Replies: 4 comments 3 replies
-
I have tried many ways of writing, but the sibling components are still re-rendered const initialState = [
{
x: 0,
y: 0
},
{
x: 100,
y: 0
},
{
x: 200,
y: 0
},
]
const data = atom({
key: 'data',
default: initialState
})
const state = selector({
key: 'state',
get: ({get}) => {
return get(data);
},
set: ({set}, newValue) => {
set(data, newValue)
}
}) |
Beta Was this translation helpful? Give feedback.
-
Do the siblings share a parent that is subscribed to the recoil state? If so that'll cause a re-render of the parent and its corresponding children. To prevent that, make sure to isolate components reading from Recoil so that state updates don't cause re-renders high in the tree |
Beta Was this translation helpful? Give feedback.
-
You can isolate them by assigning ID to that component with atom, and then re-assign that to the atomFamily. You then trigger that ID with the event with Recoil selector, and return others. It won't work all the time, but will work on your case. |
Beta Was this translation helpful? Give feedback.
-
I tried a lot of writing methods and still did not prevent sibling components from updating
![Apr-25-2022 17-42-43](https://user-images.githubusercontent.com/23691655/165064192-415447c2-aac5-4163-b7cd-262cdd47e06a.gif)
Beta Was this translation helpful? Give feedback.
All reactions