-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (33 loc) · 1.1 KB
/
index.js
File metadata and controls
41 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import React, { useState } from 'react';
import ReactMarkdown from 'react-markdown';
const MarkdownEditor = () => {
const [markdown, setMarkdown] = useState('type markdown here');
const data = [
[
{ name: 'John', age: 25 },
{ name: 'Jane', age: 30 }
],
[
{ name: 'Bob', age: 40 }
]
];
const names = data.flatMap(group => group.map(person => person.name));
console.log(names);
const ages = data.flatMap(group => group.map(person => person.age));
console.log(ages);
const handleMarkdownChange = (event) => {
setMarkdown(event.target.value);
};
const reverseSentence = () => {
const reversed = markdown.split(' ').reverse().join(' ');
const capitalized = reversed.charAt(0).toUpperCase() + reversed.slice(1);
setMarkdown(capitalized);
};
return (
<div>
<textarea value={markdown} onChange={handleMarkdownChange} />
<ReactMarkdown>{markdown}</ReactMarkdown>
</div>
);
};
export default MarkdownEditor;