Created
August 31, 2021 05:55
-
-
Save nishio/7098737a8fda9da399309cbb159afadc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
clicking the button updates global.y, but Comp1 re-renders