aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-04-05 16:32:44 +0300
committereug-vs <eug-vs@keemail.me>2020-04-05 16:32:44 +0300
commit5abf2d02bd4d11097b2650861195cf605e42bbf7 (patch)
treeb8fb789dc6687df99392c09990e0f27bc71fb9de
parent1a00cd504ff60f1749327ebc3896a4641d28670e (diff)
downloadreact-benzin-5abf2d02bd4d11097b2650861195cf605e42bbf7.tar.gz
fix: update markdown on hook
-rw-r--r--src/lib/Markdown/Markdown.tsx7
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')} />
};