I have a component that look like this where I clear the state on unmount, however this is causing me problems. After the component has unmounted, the state is successfully cleared but then I get an error saying undefined is not an object (evaluating someState.first)
. I don't understand why this is still being rendered after unmount, from what I understand after a component has been unmounted the component shouldn't render anymore?
const SomeComponent = () => {
const [someState, setSomeState] = ({
first: 'John',
last: 'Doe'
});
useEffect(()=>{
someFunction();
return () => {setSomeState()}
}, []);
const someFunction = () => {
setSomeState({
first: 'John',
last: 'Doe',
});
}
return (
<View>
<Text>{someState.first + ' ' + someState.last}</Text>
</View>
)
}