Skip to content

Commit c72dd31

Browse files
committedMar 21, 2024·
refactor: don't throw if nothing is passed, just render nothing
1 parent 4f752c8 commit c72dd31

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed
 

‎.changeset/few-rats-poke.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"markdown-to-jsx": patch
3+
---
4+
5+
Default `children` to an empty string if no content is passed.

‎index.compiler.spec.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ afterEach(() => ReactDOM.unmountComponentAtNode(root))
1717
it('should throw if not passed a string (first arg)', () => {
1818
expect(() => compiler('')).not.toThrow()
1919
// @ts-ignore
20-
expect(() => compiler()).toThrow()
20+
expect(() => compiler()).not.toThrow()
2121
// @ts-ignore
2222
expect(() => compiler(1)).toThrow()
2323
// @ts-ignore

‎index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ function getTag(tag: string, overrides: MarkdownToJSX.Overrides) {
11071107
}
11081108

11091109
export function compiler(
1110-
markdown: string,
1110+
markdown: string = '',
11111111
options: MarkdownToJSX.Options = {}
11121112
) {
11131113
options.overrides = options.overrides || {}
@@ -1946,7 +1946,7 @@ const Markdown: React.FC<{
19461946
[key: string]: any
19471947
children: string
19481948
options?: MarkdownToJSX.Options
1949-
}> = ({ children, options, ...props }) => {
1949+
}> = ({ children = '', options, ...props }) => {
19501950
if (process.env.NODE_ENV !== 'production' && typeof children !== 'string') {
19511951
console.error(
19521952
'markdown-to-jsx: <Markdown> component only accepts a single string as a child, received:',

0 commit comments

Comments
 (0)
Please sign in to comment.