diff --git a/.changeset/few-rats-poke.md b/.changeset/few-rats-poke.md new file mode 100644 index 00000000..ae97061e --- /dev/null +++ b/.changeset/few-rats-poke.md @@ -0,0 +1,5 @@ +--- +"markdown-to-jsx": patch +--- + +Default `children` to an empty string if no content is passed. diff --git a/index.compiler.spec.tsx b/index.compiler.spec.tsx index 99b593e1..69e053a2 100644 --- a/index.compiler.spec.tsx +++ b/index.compiler.spec.tsx @@ -17,7 +17,7 @@ afterEach(() => ReactDOM.unmountComponentAtNode(root)) it('should throw if not passed a string (first arg)', () => { expect(() => compiler('')).not.toThrow() // @ts-ignore - expect(() => compiler()).toThrow() + expect(() => compiler()).not.toThrow() // @ts-ignore expect(() => compiler(1)).toThrow() // @ts-ignore diff --git a/index.tsx b/index.tsx index 80fb5f32..62c8c79c 100644 --- a/index.tsx +++ b/index.tsx @@ -1107,7 +1107,7 @@ function getTag(tag: string, overrides: MarkdownToJSX.Overrides) { } export function compiler( - markdown: string, + markdown: string = '', options: MarkdownToJSX.Options = {} ) { options.overrides = options.overrides || {} @@ -1946,7 +1946,7 @@ const Markdown: React.FC<{ [key: string]: any children: string options?: MarkdownToJSX.Options -}> = ({ children, options, ...props }) => { +}> = ({ children = '', options, ...props }) => { if (process.env.NODE_ENV !== 'production' && typeof children !== 'string') { console.error( 'markdown-to-jsx: component only accepts a single string as a child, received:',