-
Notifications
You must be signed in to change notification settings - Fork 463
Expand file tree
/
Copy pathMarkdownFileExample.tsx
More file actions
39 lines (34 loc) · 1.03 KB
/
MarkdownFileExample.tsx
File metadata and controls
39 lines (34 loc) · 1.03 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
import { useEffect, useState } from 'react';
import { StyleSheet, ScrollView, SafeAreaView, Text } from 'react-native';
import { Asset } from 'expo-asset';
import Markdown from 'react-native-markdown-renderer';
/* eslint-disable @typescript-eslint/no-require-imports */
const mdAsset = require('../example_test.md');
export default function MarkdownFileExample() {
const [copy, setCopy] = useState<string | null>(null);
useEffect(() => {
(async () => {
const asset = Asset.fromModule(mdAsset);
await asset.downloadAsync();
const uri = asset.localUri || asset.uri;
const response = await fetch(uri);
setCopy(await response.text());
})();
}, []);
return (
<SafeAreaView style={styles.safe}>
<ScrollView contentContainerStyle={styles.content}>
{copy ? <Markdown>{copy}</Markdown> : <Text>Loading...</Text>}
</ScrollView>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
safe: {
flex: 1,
backgroundColor: '#fff',
},
content: {
padding: 16,
},
});