diff options
author | eug-vs <eug-vs@keemail.me> | 2020-04-05 16:32:44 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-04-05 16:32:44 +0300 |
commit | 5abf2d02bd4d11097b2650861195cf605e42bbf7 (patch) | |
tree | b8fb789dc6687df99392c09990e0f27bc71fb9de /src/lib/Markdown | |
parent | 1a00cd504ff60f1749327ebc3896a4641d28670e (diff) | |
download | react-benzin-5abf2d02bd4d11097b2650861195cf605e42bbf7.tar.gz |
fix: update markdown on hook
Diffstat (limited to 'src/lib/Markdown')
-rw-r--r-- | src/lib/Markdown/Markdown.tsx | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/lib/Markdown/Markdown.tsx b/src/lib/Markdown/Markdown.tsx index aee96e9..09ad54a 100644 --- a/src/lib/Markdown/Markdown.tsx +++ b/src/lib/Markdown/Markdown.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import axios from 'axios'; import Section from './Section'; @@ -10,6 +10,11 @@ interface PropTypes { 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')} /> }; |