Created
August 22, 2021 06:31
-
-
Save tacigar/1ce0f0619d419bb743c77891ccf87375 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
import { useCallback, useState, useEffect } from "react"; | |
const X = () => { | |
const [count, setCount] = useState(0); | |
const handleClick = useCallback(() => { | |
setCount((prev) => prev + 1); | |
}, []); | |
return <button onClick={handleClick}>Button1 ({count})</button>; | |
}; | |
const Y = ({ children }) => { | |
useEffect(() => { | |
console.log("children are updated"); | |
}, [children]); | |
return <div>{children}</div>; | |
}; | |
function App() { | |
const [count, setCount] = useState(0); | |
const handleClick = useCallback(() => { | |
setCount((prev) => prev + 1); | |
}, []); | |
return ( | |
<div> | |
<button onClick={handleClick}>Button2 ({count})</button> | |
<Y> | |
<X /> | |
</Y> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment