-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
Given the following example my understanding is that Component
should only re-render when value
changes. But it seems that because useSelector
internally uses use
which uses useState
you are essentially subscribing to the entire state update but just returning a filtered value? So Component
re-renders whenever anything in state changes? Or have I misunderstood something?
// state.js
export const exampleState = newRidgeState({ count: 0, value: 0 });
setInterval(() => {
// we are only updating the count value
exampleState.set(x => ({...x, count: x.count + 1 }));
}, 100);
// component.js
const Component = ({ children }) => {
console.log("Render: ExampleInner");
// we want to subscribe to only changes to value and only rerender if value changes
const exampleValue = exampleState.useSelector(x => x.value);
return ( ... );
};
Metadata
Metadata
Assignees
Labels
No labels