|
|
|
|
|
by lj3
2691 days ago
|
|
I do not imply the use of Context. useState() hooks into the local state of whatever component runs it. For example, if you have the following hook: function useMagicNumber(default) {
const [magicNumber, setMagicNumber] = useState(default)
return [magicNumber, setMagicNumber]
}
And the following two components that use said hook: function ExampleA({}) => {
const [magicNumber, setMagicNumber] = useMagicNumber(1)
console.log(magicNumber) // 1
}
function ExampleB({}) => {
const [magicNumber, setMagicNumber] = useMagicNumber(2)
console.log(magicNumber) // 2
}
ExampleA and ExampleB share the same code that's run in the hook useMagicNumber, but the state reflected is unique to the component. |
|