[URGENT!!! QUESTION]: How to implement LocalStorage in reactjs project??
Question
I am trying to implement localstorage in reactjs app, it is for some reason not storing data in localstorage
useEffect(() => {
const templateComponent = JSON.parse(
localStorage.getItem("gjs-components")
);
console.log(templateComponent);
const templateStyle = JSON.parse(localStorage.getItem("gjs-style"));
console.log(templateStyle);
const editor = grapesjs.init({
container: "#editor",
width: "100vw",
height: "100vh",
styleManager: {
clearProperties: true,
},
components: JSON.parse(localStorage.getItem("gjs-components")),
style: JSON.parse(localStorage.getItem("gjs-style")),
storageManager: {
id: "gjs-",
type: "local",
autosave: true,
autoload: true,
stepsBeforeSave: 1,
},
});
Answers (1)
The local storageManager does all the job for you, so you don't need to perform all those manual stuff you're doing now. So leave the storageManager option and remove the rest.
ps. be careful with useEffect, add an empty array as dependency or it will recall the init on each render...
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2118
[Question] Save configuration of dynamic blocks into HTML? (Countdown, Slider)
I am trying to save the template data into the database. Currently I have it working successfully. It posts the Assets, Components, Styles,...
Issue #4196
BUG: Ids gets changed while trying to set components on the canvas using json
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Reproducible demo link no link Desc...
Issue #3627
[QUESTION]: I'm trying to duplicate the page, but the styles are not geting applied due to the Ids, changes to -2,-3 at the end.
This is what my function looks like. I am trying duplicate the page, the HTML part is fine but as css is applied through ids, when a new pa...
Issue #2055
[QUESTION]: How to remove the components correctly?
I want to remove the components programmatically, the following is my code snippet. After the components have been removed, then undo the d...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.