Skip to content

Commit

Permalink
docs: add an example of server side rendering with useRemarkSync
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianMurphy committed Jul 8, 2021
1 parent d55c5e2 commit ea5a79b
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const ExampleComponent = () => {

useEffect(() => {
setMarkdownSource('# markdown header');
}, [])
}, []);

return reactContent;
};
Expand Down Expand Up @@ -66,6 +66,23 @@ const ExampleComponent = () => {
export default ExampleComponent;
```

### Server side rendering

```tsx
import React from 'react';
import { useRemarkSync } from 'react-remark';

const ExampleComponent = () => {
const reactContent = useRemarkSync('# markdown header');

return reactContent;
};

export default ExampleComponent;
```

:notebook: Note that some remark plugins are async, these plugins will error if used with `useRemarkSync`.

[More examples of usage as hook in storybook.](https://remarkjs.github.io/react-remark/?path=/story/remark-hook)

### As a component
Expand Down Expand Up @@ -160,7 +177,7 @@ const [reactContent, setMarkdownSource] = useRemark({
rehypePlugins: [rehypeSlug, rehypeAutoLinkHeadings],
rehypeReactOptions: {
components: {
p: props => <p className="custom-paragraph" {...props} />,
p: (props) => <p className="custom-paragraph" {...props} />,
},
},
});
Expand All @@ -183,7 +200,7 @@ import rehypeAutoLinkHeadings from 'rehype-autolink-headings';
rehypePlugins={[rehypeSlug, rehypeAutoLinkHeadings]}
rehypeReactOptions={{
components: {
p: props => <p className="custom-paragraph" {...props} />,
p: (props) => <p className="custom-paragraph" {...props} />,
},
}}
>
Expand Down

0 comments on commit ea5a79b

Please sign in to comment.