aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Markdown
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-04-03 03:30:16 +0300
committereug-vs <eug-vs@keemail.me>2020-04-03 03:30:16 +0300
commita2877c2844825853b8913a07a40f814fc03ac999 (patch)
tree0e89a301327b75506c49599cff2bc7329a85d0c0 /src/lib/Markdown
parenteee96f01e29ddb8b95e9429c4e584fe6e7e7faec (diff)
downloadreact-benzin-a2877c2844825853b8913a07a40f814fc03ac999.tar.gz
feat: support Markdown by url
Diffstat (limited to 'src/lib/Markdown')
-rw-r--r--src/lib/Markdown/Markdown.tsx15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/lib/Markdown/Markdown.tsx b/src/lib/Markdown/Markdown.tsx
index a3ffc38..944ac86 100644
--- a/src/lib/Markdown/Markdown.tsx
+++ b/src/lib/Markdown/Markdown.tsx
@@ -1,10 +1,12 @@
-import React from 'react';
+import React, { useState, useEffect } from 'react';
+import axios from 'axios';
import ContentSection from '../ContentSection/ContentSection';
interface PropTypes {
- data: string;
+ data?: string;
+ url?: string;
}
interface RawLinesPropType {
@@ -14,7 +16,7 @@ interface RawLinesPropType {
const header = (level: number): string => {
return `^#{${level}} .*$`;
-};
+}
const Content: React.FC<RawLinesPropType> = ({ rawLines }) => {
const plainText = rawLines.join();
@@ -47,9 +49,10 @@ const Level: React.FC<RawLinesPropType> = ({ rawLines, level = 0 }) => {
);
}
-const Markdown: React.FC<PropTypes> = ({ data }) => {
- const rawLines = data.split('\n');
- return <Level rawLines={rawLines} />
+const Markdown: React.FC<PropTypes> = ({ data, url }) => {
+ const [markdown, setMarkdown] = useState<string>(data || '');
+ if (url) axios.get(url).then(response => setMarkdown(response.data));
+ return <Level rawLines={markdown.split('\n')} />
};