How to save the current stage of the GrapesJS editor

Viewed 72

I have created a no-code tool using GrapesJS. After closing the tool, the contents get refreshed and my previously stored contents are gone. I want to retain the old contents even after closing the tool. How can I implement this?

1 Answers

You can save your editor changes by grapesjs storage manager

this storage manager can save your changes in browser local storage and also can save remotely to maybe in your DB.

the follwoing code will save to browser local storage.

 const editor = grapesjs.init({
  ...
  // Default configurations
  storageManager: {
    type: 'local', // Storage type. Available: local | remote
    autosave: true, // Store data automatically
    autoload: true, // Autoload stored data on init
    stepsBeforeSave: 1, // If autosave is enabled, indicates how many changes are necessary before the store method is triggered
    // ...
    // Default storage options
    options: {
      local: {/* ... */},
      remote: {/* ... */},
    }
  },
});

for more details refer to this https://grapesjs.com/docs/modules/Storage.html#configuration

Related