Skip to content

Context store is not updated after rerender #950

Answered by Karmalakas
Karmalakas asked this question in Q&A
Discussion options

You must be logged in to vote

OMG... It's as simple as adding a key prop to the component, which holds the context provider. Prop should be updated depending on the changed main state...

This works as expected

const Buttons = () => {
  const toggle = useStoreState((state) => state.toggle);

  console.log("BUTTONS", toggle);

  return (
    <ContextEnable.Provider key={toggle} runtimeModel={{ enable: toggle }}>
      <Button />
      <Button />
    </ContextEnable.Provider>
  );
};

Thanks again for pointing to the right direction 🙏

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@Karmalakas
Comment options

Comment options

You must be logged in to vote
3 replies
@Karmalakas
Comment options

@jmyrland
Comment options

@Karmalakas
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Karmalakas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants