From a2877c2844825853b8913a07a40f814fc03ac999 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Fri, 3 Apr 2020 03:30:16 +0300 Subject: feat: support Markdown by url --- src/lib/Markdown/Markdown.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/lib/Markdown') 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 = ({ rawLines }) => { const plainText = rawLines.join(); @@ -47,9 +49,10 @@ const Level: React.FC = ({ rawLines, level = 0 }) => { ); } -const Markdown: React.FC = ({ data }) => { - const rawLines = data.split('\n'); - return +const Markdown: React.FC = ({ data, url }) => { + const [markdown, setMarkdown] = useState(data || ''); + if (url) axios.get(url).then(response => setMarkdown(response.data)); + return }; -- cgit v1.2.3