This seems unordinary. I’m attempting to simply setState on mount, but it’s just going blank on me.
const [info, setState] = useState({
user_1: '',
user_2: '',
});
useEffect(() => {
var personal_1 = window.localStorage.getItem('personal_1');
var personal_2 = window.localStorage.getItem('personal_2');
console.log(personal_1);
if (personal_1 !== null && personal_2 !== null) {
console.log('Make it easy')
setState({
...info,
user_1: personal_1,
user_2: personal_2
})
}
}, [])
useEffect(() => {
console.log('User personal_1 was changed to', info.user_1);
}, [info.user_1])
When I log the effects of this component mounting,
it shows
personal_1
Make it easy
User personal_1 was changed to
For some reason instead of setting the state on mount to the value from local storage, it just goes blank. I thought it was probably being set back to being blank from somewhere else in the component, but the info.personal_1 hook only gets called once. Does anyone know why it might potentially be setting the local storage item, but then going blank when the storage item is a normal string?