Skip to content

Commit

Permalink
refactor: don't throw if nothing is passed, just render nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
quantizor committed Mar 21, 2024
1 parent 4f752c8 commit c72dd31
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-rats-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"markdown-to-jsx": patch
---

Default `children` to an empty string if no content is passed.
2 changes: 1 addition & 1 deletion index.compiler.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {}
Expand Down Expand Up @@ -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: <Markdown> component only accepts a single string as a child, received:',
Expand Down

0 comments on commit c72dd31

Please sign in to comment.