[Question] React with GrapeJS
Question
Greetings, I did searches and could not particularly find a solution to my problem. Currently, I am trying to integrate my React App with GrapeJS.
`import React, { Component } from 'react';
import './GrapesSrc/grapes.min.js';
import GrapesIndex from 'grapejs';
class GrapesEditor extends Component {
constructor(props){
super(props);
}
shouldComponentUpdate(){
return false
}
componentDidMount(){
const editor = grapesjs.init({
container : '#gjs',
components: '<div class="txt-red">Hello world!</div>',
style: '.txt-red{color: red}',
});
}
render() {
return (
<div id ='gjs'>
</div>
);
}
}
export default GrapesEditor;
`
I have tried using the CDN, including it into my index.html file but all of that still had the error of grapesjs being undefined.
I tried to import './GrapesSrc/grapes.min.js' directly. Creating a new folder with the codes in the CDN but it still did not work.
I am not sure if this is a valid question or not since there was one issue that seemed similar to this that was rejected.Answers (3)
@sakshigarg9 add grapesjs via npm, then in your code just use import grapesjs from 'grapesjs' It will work, without any need to update the webpack configuration
@Silavin Have you succeed with integrating grape and react?
If you're using webpack to build your React app, you can include it as a plugin. It'll pull it from node_modules.
plugins: [ new webpack.ProvidePlugin({ grapesjs: "grapesjs" }) ],
This worked for me.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1864
[QUESTION] Best way to listen to changes on the final HTML?
Hi, I just had a quick question because I could not figure out how to do it or did not find an issue related to it. I am just trying to cal...
Issue #1818
[Question]: Making grapesjs working with angular7 and material
I'm trying to integrate the library with Angular7, but got problem when moving container <div id="gjs"></div>into the material component (s...
Issue #1960
[QUESTION] Dynamic class generation with a template
Hi there ! I am wondering if there is a way to force the dynamic class generation (of the form cXXXXX which happens when I drag'n'drop a co...
Issue #1707
Find images links in the editor
I am trying to integrate GrapesJs in reactJs. Can you please help me out with the below question w.r.t GrapesJs-React, • Is there a way to...
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.