Facebook uses a single-page application made by react, so how does it save page state data?

that is, refresh the page user data, the page status is still there, how is this done?

Jun.29,2022

if the refresh of the system is used, the data state will not be saved. By refresh, you mean routing jump?


this is simple, just use localStorage directly, which is often used in my projects.

getInitialState: function() {
    var selectedOption = localStorage.getItem( 'SelectedOption' ) || 1;
    return {
        selectedOption: selectedOption
    };
},

setSelectedOption: function( option ) {
    localStorage.setItem( 'SelectedOption', option );
    this.setState( { selectedOption: option } );
}
Menu