GitHub Documentation

How to deserialize stored state snapshot?



  • Hi,
    I am new here and I am building a VTT (virtual table top) where I store the board state on room dispose as JSON.
    On create I would like to deserialize it into the new state.

    Is there a quick way of doing it or do I need to nest constructors to consume the object?

    Many thanks.
    Joel


  • administrator

    Hi @AllNamesRTaken, welcome! 👋

    You should be able to do the following:

    const snapshot = this.state.toJSON();
    // ...store snapshot JSON into the database
    
    // ...let's restore the snapshot
    this.state.assign(snapshot);
    

    Let me know if that works for you!


 

© 2021 Lucid Sight, Inc