-
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
80 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
title: React Refs | ||
--- | ||
|
||
## Extract context as a `ref` | ||
|
||
In order to access the context properties of your editor from externally the following snippet | ||
should work. | ||
|
||
It makes use of the less well known `useImperativeHandle` to attach the context from the editor to | ||
the `ref` within a forward ref component. | ||
|
||
```tsx | ||
import { forwardRef, useImperativeHandle, FC } from 'react'; | ||
import { useRemirror } from 'remirror/react'; | ||
|
||
let EditorWithRef = (props: {}, ref: RemirrorContext) => { | ||
const context = useRemirror(); | ||
const { getRootProps } = context; | ||
|
||
useImperativeHandle(ref, () => context); | ||
|
||
return <div {...getRootProps} />; | ||
}; | ||
|
||
EditorWithRef = forwardRef(EditorWithRef); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
title: 'Frequently asked questions' | ||
--- | ||
|
||
Some of the answers outlined here may be helpful to you if you're stuck somewhere. They're questions | ||
that are asked quite frequently on GitHub and in our [discord](https://remirror.io/chat) channel. | ||
|
||
### Is there any way to get the value of the editor already parsed to HTML? | ||
|
||
There's are methods available in `remirror/core`. `toHtml` which converts the provided node to a | ||
HTML string, and `fromHtml` which takes the html string you've provided and converts it into a value | ||
that can be used within remirror. | ||
|
||
To get the html string from the editor the following should work well for you. | ||
|
||
```tsx | ||
import { toHtml } from 'remirror/core'; | ||
|
||
const htmlString = toHtml({ node: state.doc, schema: state.schema }); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
febad9e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://remirror.io as production
🚀 Deployed on https://5f44022a804ed29a1c61b101--remirror.netlify.app