Skip to content

Instantly share code, notes, and snippets.

@WooJongSeon
Created May 6, 2021 13:22
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 WooJongSeon/98022d22f425e0ca3299f775ad536924 to your computer and use it in GitHub Desktop.
Save WooJongSeon/98022d22f425e0ca3299f775ad536924 to your computer and use it in GitHub Desktop.
import { useCallback, useEffect, useMemo, useState } from 'react'
function Info({ blue, red }: any) {
useMemo(() => getBlue(blue), [blue])
useMemo(() => getRed(red), [red])
// getBlue(blue)
// getRed(red)
return (
<div>
<p>blue {blue}</p>
<p>red {red}</p>
</div>
)
}
function getBlue(value: any) {
console.log('get blue')
}
function getRed(value: any) {
console.log('get red')
}
function App() {
const [redValue, setRedValue] = useState(0)
const [blueValue, setBlueValue] = useState(0)
function plusBlueValue() {
setBlueValue(blueValue + 1)
}
function plusRedValue() {
setRedValue(redValue + 1)
}
return (
<div className="App">
<br/>
<button onClick={plusBlueValue}>plus blue value</button>
<button onClick={plusRedValue}>plus red value</button>
<br/>
<Info blue={blueValue} red={redValue}/>
</div>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment