Skip to content

Instantly share code, notes, and snippets.

@anupkgurung
Created July 6, 2022 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anupkgurung/3f5980ce38a254af771ab3c92d459141 to your computer and use it in GitHub Desktop.
Save anupkgurung/3f5980ce38a254af771ab3c92d459141 to your computer and use it in GitHub Desktop.
export const ComponentA = () => {
const [counter, setCounter] = useState(0)
return (
<>
<div><b>i am the at {counter} counter</b></div>
<ComponentB setCounter={setCounter}/>
<ComponentC setCounter={setCounter}/>
</>
)
}
export const ComponentB = ({setCounter}) => {
return (
<>
<button onClick={()=>setCounter(counter => counter+1)}>Add One</button>
</>
)
}
export const ComponentC = ({setCounter}) => {
return (
<>
<button onClick={()=>setCounter(counter => counter+2)}>Add Two</button>
</>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment