You need to add your state to the dependency array
const [organizationName, setOrganizationName] = React.useState('');
React.useEffect(() => {
const unsubscribeNavigationFocus = props.navigation.addListener(
'focus',
async () => {
try {
console.log(organizationName, 'OLD VALUE');
// }
} catch (error) {
console.log('inside error');
console.log(error);
} finally {
}
}
);
return unsubscribeNavigationFocus;
}, [props.navigation, organizationName]);
Use the official ESLint plugin for React to catch such issues https://www.npmjs.com/package/eslint-plugin-react-hooks
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…