Add an `editor` prop to the `Editor` react component.
See original GitHub issueDo you want to request a feature or report a bug?
Feature
What’s the expected behavior?
Currently, you can only get the editor
controller instance by using ref
s. I think being able to instantiate your Editor
controller above your component in the tree, and pass it as a prop to the editor would improve the ergonomics a bit when you need to interact with your editor outside of plugins. This can also sort of be accomplished with renderEditor
, but at the expense of a bit of clarity.
Example:
function App() {
const editor = new SlateEditor({plugins})
return (
<Editor
editor={editor} // could be `controller` maybe?
/>
)
}
If this were implemented, we could remove ref support and cleanup the editor component code a bit. You could still technically do the same thing, you’d just have grab the editor from the props of your ref vs acting on your ref directly.
Thoughts?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:14 (9 by maintainers)
Top Results From Across the Web
React Editor Demo: Add an Editor Component the Easy Way
In this article, you'll learn how to easily add a React Rich Text Editor with the help of the KendoReact component library and...
Read more >How To Customize React Components with Props
To start, open src/App.js in a text editor. This is the root component that is injected into the page. All components will start...
Read more >How to Build a Code Editor with React that Compiles and ...
The editor receives the props onChange , language , code , and theme from its parent component, which is Landing.js .
Read more >Build rich text editors in React using Draft.js and react-draft ...
The react-draft-wysiwyg library offers a rich text editor ... Add the className props to the Editor component and the relevant styles to ...
Read more >React component - CKEditor 5 Documentation
The easiest way to use CKEditor 5 in your React application is by choosing one of the rich text editor builds. Additionally, it...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve been thinking about this more and doing some experimenting in our code base. I do think we should work away from the
ref
approach for a couple reasons:I’m not sure if this is best, but here’s what I’m thinking so far:
Basic Usage
This way,
editor
always exists vs in the ref approach whereEditor
has to render first.A few thoughts in response:
View-layer-specific props I think there are two options here. One is that these are defined in the hook, and the hook also gives you a component:
The other is that anything that gets passed directly to the DOM node is passed to the component. I think it should behave this way either way, so it makes sense to support it.
Value Yes, I think you’d pass value to the hook also. For default value, we could still support that with state inside the hook.
I do exactly this in our application. I love it. I’d recommend
useSlate
as the main hook.I’m down to put some time into working out a proof of concept whether we go this way or not. The biggest thing for me is getting ConvertKit’s editors up to date with the latest versions first, so it might be a little bit before I get started.