Using LocalStorage with React?

后端 未结 5 848
没有蜡笔的小新
没有蜡笔的小新 2020-12-13 09:08

From what I am experiencing so far, it doesn\'t seem like ReactJS updates with the state of localStorage. My code below.

var Frr = React.createClass({
getIni         


        
5条回答
  •  情书的邮戳
    2020-12-13 09:38

    The .setItem() local storage function returns undefined. You need to perform the local storage update and then return the new state object:

    switchoff: function(){
        localStorage.setItem('state', 'off');
        this.setState({lights: 'off'}); 
    },
    

提交回复
热议问题