aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Markdown/Markdown.tsx
blob: 0a71fd3592fc70cd9f9b1b8008e01d57e36327a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import React, { useState, useEffect } from 'react';
import axios from 'axios';

import Section from './Section';

interface PropTypes {
  data?: string;
  url?: string;
}

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(/\r?\n/)} />
};


export default Markdown;