I have a hook like so
export function useMyStuff(value) {
const [info1, setinfo1] = useState()
const [info2, setinfo2] = useState()
useEffect(() => {
const asyncFunc = () => {
if (???) {
setinfo1(value) // this updates MyComponent as expected
... wait some time ...
setinfo2(value) // PROBLEM: this updates MyComponent
}
}
asyncFunc()
}, [value])
...
return {
info1, info2
}
}
And my component
export default function MyComponent() {
const [value, setValue] = useState()
const { info1 } = useMyStuff(value)
// PROBLEM: component rerenders on info2 change (and info1 of course)
return (...)
}
I believe my component should only update when I update info1
, however it's updating when only info2
updates as well. What should my structure be to only update when info1
updates?