aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-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')} />
};