Undefined for multiple page manager in React
Question
Hi, please what is the best way to implement multiple page manager in a react app.
I have successfully implemented this without page manager like so:
useEffect(() => {
const editor = grapesjs.init({
container: "#editor",
storageManager: {
type: "remote",
stepsBeforeSave: 2,
contentTypeJson: true,
storeComponents: true,
storeStyles: true,
storeHtml: true,
storeCss: true,
// id: "my-",
urlStore: `some-url`,
urlLoad: `some-url`,
headers: {
"Content-Type": "application/json",
},
credentials: 'omit',
},
panels: { defaults: [] },
plugins: [gjsPresetWebpage],
pluginsOpts: {
gjsPresetWebpage: {},
},
});
editor.Panels.getButton('options', 'sw-visibility').set('active', true);
setEditor(editor);
}, []);
return (
<Wrapper bgColor={bgColor} hoverColor={hoverColor}>
<div id="editor"></div>
</Wrapper>
);
For the page manager implementation I try this:
useEffect(() => {
const editor = grapesjs.init({
container: "#editor",
storageManager: {
type: "remote",
stepsBeforeSave: 2,
contentTypeJson: true,
storeComponents: true,
storeStyles: true,
storeHtml: true,
storeCss: true,
// id: "my-",
urlStore: `some-url`,
urlLoad: `some-url`,
headers: {
"Content-Type": "application/json",
},
credentials: 'omit',
},
pageManager: true, // here
panels: { defaults: [] },
plugins: [gjsPresetWebpage],
pluginsOpts: {
gjsPresetWebpage: {},
},
});
editor.Panels.getButton('options', 'sw-visibility').set('active', true);
const pageManager = editor.Pages; // here
pageManager.getAll() // here
console.log(pageManager) // undefined
setEditor(editor);
}, []);
Here, I get undefined for page manager. I would appreciate any help please.
Thanks
Answers (2)
I think you're just using an old version of GrapesJS
Thanks for reporting this, @Ubanna.
Great question about undefined for multiple page manager in React. 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 #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 #3420
[URGENT!!! QUESTION]: How to implement LocalStorage in reactjs project??
I am trying to implement localstorage in reactjs app, it is for some reason not storing data in localstorage
Issue #4187
Editor Destroy method throws an error in React
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome 98 Reproducible demo link https://c...
Issue #3455
Style gets wiped out when inserting components in multiple page using Page Manager
Version: 0.17.3 What is the expected behavior? Style should be retained across multiple pages Describe the bug detailed We have use case wh...
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.