I have a scenario where our application has multiple functions that sit within componentDidUpdate
. In each of the functions they check to see if their specific data is updated. For example:
componentDidUpdate(prevProps) {
this.handleFoo(prevProps)
this.handleMoreFoo(prevProps)
}
handleFoo(prevProps){
if(this.props.foo != prevProps.foo){
//Do Something
}
}
handleMoreFoo(prevProps){
if(this.props.moreFoo != prevProps.moreFoo){
//Do Something
}
}
I have been looking at the useEffect
hook and was wondering if I could chop out that initial check in each of these functions and utilize the []
in useEffect
and only call one of these functions if their specific key is updated like this:
useEffect(() => {
if(fooKey){ handleFoo() }
if(moreFoo) { handleMoreFoo() }
}, [fooKey, moreFooKey])
Is this possible? Is this advisable?