I want to write the equivalent of componentDidMount so the docs tell me to use an emptyArray
useEffect(() => {
console.log(props.myProp1)
console.log(props.myProp2)
console.log('DIDMOUNT.');
}, [])
But everytime I try to access a variable that is not part of the dependency array inside the useEffect callback, the warning is:
React Hook useEffect has missing dependencies: 'props.myProp1' and 'props.myProp2'. Either include them or remove the dependency array react-hooks/exhaustive-deps
Which defeats the purpose of having an empty-array (to simulate componentDidMount) ?
With Classes I simply write
componentDidMount() {
console.log(props.myProp1)
console.log(props.myProp2)
}
, and can access any variable that the Class is aware of;
UPDATED: I voted to close the question, as a comment below pointed to a duplicate.