diff options
author | Eugene Sokolov <eug-vs@keemail.me> | 2020-04-06 17:47:20 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-06 17:47:20 +0300 |
commit | 62df0ff96fc9ab832212d223150862c7667d9ffc (patch) | |
tree | 9159c443e970ea2a0819edffbe2fe5cc101c1001 /src/lib/Markdown/Markdown.tsx | |
parent | a72027d21154ba94e26d6b96092afc9704b8288c (diff) | |
parent | 400330fe5ebd6951a97f07b6147b3af6113e034f (diff) | |
download | react-benzin-62df0ff96fc9ab832212d223150862c7667d9ffc.tar.gz |
Merge pull request #8 from eug-vs/developv3.1.0
Markdown parser
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; + |