Child component is refreshed after each update #831
Answered
by
dai-shi
camer100
asked this question in
Bug report
-
import React from "react"
import { proxy, useSnapshot } from "valtio"
const state = proxy({ count: 0 })
function Child1 () {
console.log("child1 refresh")
return <div>child1</div>
}
function Child2 () {
console.log("child2 refresh")
return <div>child2</div>
}
export default function App () {
console.log("refresh app")
const snap = useSnapshot(state)
return (
<div className="App" style={{ height: 500, padding: 20 }}>
<Child1 />
<Child2 />
{snap.count}
<button type="button" onClick={() => { state.count++ }}>aaa</button>
</div>
)
} Child1 and Child2 refresh every time, but not any update in these component. react: 18.2.0 |
Beta Was this translation helpful? Give feedback.
Answered by
dai-shi
Dec 7, 2023
Replies: 1 comment 2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Child rerenders when the parent component rerenders. It's React's default behavior.