P
Size: a a a
P
PA
componentDidMount() {
let oldState = JSON.parse(localStorage.getItem('state'));
this.setState({ ...this.state, ...oldState });
}
componentDidUpdate() {
localStorage.setItem('state', JSON.stringify({ ...this.state }));
}
PA
useEffect(() => {
let oldState = JSON.parse(localStorage.getItem('state'));
this.setState({ ...this.state, ...oldState });
}, [localStorage.setItem('state', JSON.stringify({ ...this.state }))])
IK
useEffect(() => {
let oldState = JSON.parse(localStorage.getItem('state'));
this.setState({ ...this.state, ...oldState });
}, [localStorage.setItem('state', JSON.stringify({ ...this.state }))])
VI
useEffect(() => {
let oldState = JSON.parse(localStorage.getItem('state'));
this.setState({ ...this.state, ...oldState });
}, [localStorage.setItem('state', JSON.stringify({ ...this.state }))])
PA
AD
useEffect(() => {
let oldState = JSON.parse(localStorage.getItem('state'));
this.setState({ ...this.state, ...oldState })
}, [])
// пустой массив показывает что следить на зависимостями не надо, => он сработает только один раз localStorage.setItem('state', JSON.stringify({ ...state }));
}, [state])
AD
VI
PA
useEffect(() => {
let oldState = JSON.parse(localStorage.getItem('state'));
this.setState({ ...this.state, ...oldState })
}, [])
// пустой массив показывает что следить на зависимостями не надо, => он сработает только один раз localStorage.setItem('state', JSON.stringify({ ...state }));
}, [state])
AD
PA
AP
VI
PA
VI
VI
t
t
SN