-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can you create plugins that are React components? #69
Comments
@marksboyce Hi! First of all, thanks for your interest! 👋 You can't create plugin with react currently. (only vanila js) I hope this document will help you. Thanks! |
I thought not. Thanks. |
@marksboyce Not sure if this is what you meant, but custom tools can return jsx/react components Here's a quick example:
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@Benjaminryejones Thanks, this is useful. I started down this path, but I get the feeling that the lack of native support for React will make the whole thing a lot harder. |
Hi @marksboyce, This is indeed an interesting question. I've implemented EditorJS in several React apps and there are certain issues you need to be aware of. Not only regarding the onClick handling, but also other aspects. Take a look at this example for instance: In a simple use-case where you add a React component (as I mentioned in the another issue), you end up with the following React app tree:
Because we are using I plan to write an article about how I solved this in my apps. But I do not have an ETA for the article yet. |
@natterstefan Thanks for this. Helpful to know, and please share your article, once complete. These are the sorts of issues that I'm worried about banging my head against. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
As this pattern seems pretty common, I extracted out the logic and wrote a util function: https://gist.github.com/donfour/82193ab0c138afcc8c840c7a79474db4. Hope it's useful. |
Hey @natterstefan! Did you ever figure out how to prevent custom blocks from rendering in a different DOM? I was having trouble for a few days until I realized that my custom component was rendering in a different DOM and wasn't able to access redux. |
I never figured out how to prevent it, but how to utilize and work with it instead. We ended up enriching the blocks with callbacks, that triggered state updates in the "root app" and callbacks that we're able to update the state of the block vice versa. It's definitely a workaround, but it solved our issue and insofar worked. But unfortunately, I do not have a working example I can provide anymore - I do not work at that company anymore - and therefore cannot illustrate it. I am sorry. What you must achieve is providing a "bridge" between the rendered Block and the App with callbacks you add to the I am sorry I cannot be of more help to you. |
Hey @natterstefan, I know you can't share the code/too much detail, but can share a little more detail on how you implemented the callbacks? Did you have to fork editor.js/modify its source in order to do this? I'm trying to have a react component inside of a block that can read from a react context that's higher up in the component tree but have been struggling to find a method of implementation I'm happy with. If I can get something reasonable working, I'd be happy to open source the work and add it as a contribution to editor.js if appropriate. I imagine a tool like this would make editor.js infinitely more adoptable by the react community. |
Hi, thanks for all your hard work.
I assume it isn't possible out-of-the-box to use React components as plugins, correct? It doesn't seem that way, but I'm just making sure.
Thanks.
The text was updated successfully, but these errors were encountered: