Skip to content

Components Re-rendering #18

@JakeNap

Description

@JakeNap

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions