diff options
Diffstat (limited to 'src/lib/Markdown/Markdown.tsx')
-rw-r--r-- | src/lib/Markdown/Markdown.tsx | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/lib/Markdown/Markdown.tsx b/src/lib/Markdown/Markdown.tsx new file mode 100644 index 0000000..09ad54a --- /dev/null +++ b/src/lib/Markdown/Markdown.tsx @@ -0,0 +1,24 @@ +import React, { useState, useEffect } from 'react'; +import axios from 'axios'; + +import Section from './Section'; + +interface PropTypes { + data?: string; + url?: string; +} + +const Markdown: React.FC<PropTypes> = ({ data, url }) => { + const [markdown, setMarkdown] = useState<string>(data || ''); + + useEffect(() => { + if (!url) setMarkdown(data || ''); + }, [data, url]); + + if (url) axios.get(url).then(response => setMarkdown(response.data)); + return <Section rawLines={markdown.split('\n')} /> +}; + + +export default Markdown; + |