So my solution was to also set localStorage
when setting my state and then get the value from localStorage
again inside of the getInitialState
callback like so:
getInitialState: function() {
var selectedOption = localStorage.getItem( 'SelectedOption' ) || 1;
return {
selectedOption: selectedOption
};
},
setSelectedOption: function( option ) {
localStorage.setItem( 'SelectedOption', option );
this.setState( { selectedOption: option } );
}
I'm not sure if this can be considered an Anti-Pattern but it works unless there is a better solution.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…