[rehype-react] Add Fragment option, update which options are optional (#41600)

* [rehype-react] Add Fragment option

Usually this will be `React.Fragment`, but it accepts any component.

* [rehype-react] Update which options are optional

Most options have healthy defaults. Only `createElement` is required.

* [rehype-react] Update version number

* [rehype-react] Update tests to include Fragment option
This commit is contained in:
Johan Fagerberg 2020-01-21 22:14:03 +01:00 committed by Ben Lichtman
parent 4331db7e1c
commit d01dbee933
2 changed files with 4 additions and 2 deletions

View File

@ -1,4 +1,4 @@
// Type definitions for rehype-react 3.1
// Type definitions for rehype-react 4.0
// Project: https://github.com/rhysd/rehype-react
// Definitions by: Adrian Kremer <https://github.com/adriankremer>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@ -8,7 +8,8 @@ import * as React from "react";
interface Options {
createElement: typeof React.createElement;
components: {
Fragment?: React.ComponentType<{ children?: React.ReactNode }>;
components?: {
[tagName: string]: React.ComponentType<any>;
};
prefix?: string;

View File

@ -8,6 +8,7 @@ const htmlAst = {
const { Compiler: compile } = new RehypeReact({
createElement: React.createElement,
Fragment: React.Fragment,
components: {
button: () => {
return <button />;