Skip to content

Instantly share code, notes, and snippets.

@nishio
Created August 31, 2021 05:55
Show Gist options
  • Save nishio/7098737a8fda9da399309cbb159afadc to your computer and use it in GitHub Desktop.
Save nishio/7098737a8fda9da399309cbb159afadc to your computer and use it in GitHub Desktop.
const TestApp = () => {
console.log("render TestApp");
return (
<div>
<Comp1 />
<Comp2 />
</div>
);
};
const Comp1 = () => {
const [x] = useGlobal("x");
console.log("render Comp1");
return <span>{x}</span>;
};
const Comp2 = () => {
const onClick = () => {
console.log("onClick");
// setGlobal({ y: "hello" });
setGlobal((g) =>
produce(g, (g_) => {
g_.y = "hello";
})
);
};
return <button onClick={onClick}>update y</button>;
};
@nishio
Copy link
Author

nishio commented Aug 31, 2021

clicking the button updates global.y, but Comp1 re-renders

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment