How to create a custom storage manager, it doesnt set saved data from canvas, after reloading the page
Remove this one const resultKey = key.slice(4);. You're storing data with the prefix but then you're loading it without
Read full answer below βQuestion
Hello everyone, i want to save data from canvas to redux store, and it works, but after reloading the page, storage load method , doesnt set my data to builder (canvas), i dont know whats wrong, let me know if someone has any solutions.
Code example :
grapejs.init({
...///
storageManager: {
type: 'redux-storage',
autosave: false,
autoload: 1,
},
...///
});
const reduxStorage = {};
const storageManager = editor.StorageManager;
storageManager.add('redux-storage', {
load(keys, clb, clbErr) {
const result = {};
keys.forEach(key => {
const resultKey = key.slice(4);
const item = localStorage.getItem(resultKey);
const value = reduxStorage[key];
if (item) {
result[resultKey] = item;
}
});
// Might be called inside some async method
clb(result);
},
store(data, clb, clbErr) {
for (let key in data) {
reduxStorage[key] = data[key];
localStorage.setItem(key, data[key])
}
// Might be called inside some async method
clb();
}
})
storageManager.load(['gjs-css', 'gjs-components', 'gjs-styles', 'gjs-assets', 'gjs-html'], res => {
console.log(res, 'res storageManager.load()')
});
Answers (2)
Remove this one const resultKey = key.slice(4);. You're storing data with the prefix but then you're loading it without
Thanks for reporting this, @vatte21.
Great question about How to create a custom storage manager, it doesnt set saved data from canvas, after reloading the page. The recommended approach with StyleManager is to use the event-driven API.
Start here:
- Check the GrapesJS documentation for your specific module
- Look for the
on()event listener method - Most operations can be achieved by listening to editor and component events
Common patterns:
// Listen for changes
editor.on('change', () => console.log('something changed'));
// Component lifecycle
editor.on('component:mount', (c) => console.log('component ready', c));
editor.on('component:update', (c) => console.log('component updated', c));
If you're still stuck:
- Share a minimal CodeSandbox reproduction
- Include what you've already tried
- Mention your GrapesJS version
- The community is here to help!
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3222
How to refresh/re-render after new node added?
I manually add a new node into a rendered component. The visual result is OK, but impossible to save, because my style isn't with the auto-...
Issue #6685
Custom component styles are not applied after deletion and re-addition
GrapesJS version [x] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v143.0.7499.193 Reproducible demo l...
Issue #3599
@keyframes not adding even after i pass the the keyframes object
Hi @artf, I have added the let cc = editor.CssComposer; cc.setRule('.fadetop-animate', { opacity: 0, 'animation-name': 'fadeTop' }, { atRul...
Issue #4371
All editors broken after last update that broke storage manager.
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Reproducible demo link https://www....
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins βPremium plugins ship with support, regular updates, and production-ready features β save days of integration work.
Browse premium plugins βBrowse Plugin Categories
Jump directly to plugin category pages on the marketplace.