how to use context in components React? #4142
Unanswered
vizardkill
asked this question in
Q&A
Replies: 1 comment
-
The specific case is that the component that renders Grapes JS with React is not able to find the context |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am developing a component in Next JS, when I load the application I load one element in a global context, but when I call the component in the Editor, the context does not exist
This is my block:
`import { Editor } from "grapesjs";
import Navigation from "../../../common/components/core/Navigation/Navigation";
export const NavigatorWidget = (editor: Editor) => {
editor.Components.addType("Header", {
extend: "react-component",
model: {
defaults: {
component: Navigation,
stylable: false,
resizable: false,
editable: false,
draggable: true,
droppable: true,
removable: false,
},
},
isComponent: (el: any) => el.tagName === "NAVIGATION",
});
};
`
This is my component:
`/** @jsxImportSource theme-ui */
import { Fragment, Component } from "react";
// Context
import { PageDataContext } from "../../../../modules/app/context/PageProvider";
// Components
import NavigationLink from "./NavigationLink";
import Logo from "../../utils/Logo/Logo";
import SearchField from "../../utils/SearchField/SearchField";
import MobileNavigation from "./MobileNavigation";
// Icons
import { CloseIcon, MenuIcon, BagIcon } from "../../../icons";
// Styles
import * as mainStyles from "../../utils/main.styles";
import * as styles from "./Navigation.styles";
type State = {
isMenuOpen: boolean;
isLoading: boolean;
context: any;
};
type Props = {
bg: string;
color: string;
};
class Navigation extends Component<Props, State> {
static contextType = PageDataContext;
}
export default Navigation;
`
The other thing is how do I preload the JSX styles? I'm using the @theme-ui library
Beta Was this translation helpful? Give feedback.
All reactions