일기장 오늘의 App.ts는 고급 기술을 연습해보았다
- 리눅스
- 58
- 6
- 5
import { Component, createElement } from 'react';
import { Text } from 'react-native';
import { DocumentDirectoryPath, readFile, writeFile } from 'react-native-fs';
import _random from 'lodash/random';
class FileIO {
protected path = DocumentDirectoryPath + '/../Desktop/';
constructor(file_name: string) {
this.path += file_name;
}
public read() {
return readFile(this.path)
.then(content => {
return content;
})
.catch(e => {
throw new e.code + '\n' + e.message;
});
}
public write(file_content: string) {
writeFile(this.path, file_content)
.catch(e => {
throw new e.code + '\n' + e.message;
});
}
}
export default class App extends Component<undefined, { str: string }> {
constructor(props: any) {
super(props);
this.state = { str: '' };
}
protected io = new FileIO('test.txt');
async componentDidMount() {
this.io.write(_random(9).toString());
const file_str = await this.io.read();
this.setState({ str: file_str });
}
render() {
return createElement(Text, undefined, this.state.str);
}
}
분류 | 제목 | 글쓴이 | 날짜 | 조회 수 | |
---|---|---|---|---|---|
공지 | [공지] 츄르내역_240102 19 | 조유리 | 3076 | 12 | |
공지 | [공지] 공지사항_220412 30 | 조유리 | 6539 | 64 | |
일기장 |
이미지
|
Sso! | 31 | 1 | |
일기장 |
기본
|
메르시장인 | 51 | 7 | |
일기장 |
기본
|
메르시장인 | 60 | 7 | |
일기장 |
기본
|
메르시장인 | 82 | 14 | |
일기장 |
기본
|
메르시장인 | 59 | 9 | |
일기장 |
기본
|
메르시장인 | 55 | 5 | |
일기장 |
기본
|
메르시장인 | 41 | 5 | |
일기장 |
기본
|
메르시장인 | 44 | 8 | |
일기장 |
기본
|
메르시장인 | 69 | 11 | |
일기장 |
기본
|
메르시장인 | 64 | 8 | |
일기장 |
기본
|
철이두개면두철 | 28 | 3 | |
일기장 |
기본
|
메르시장인 | 46 | 8 | |
일기장 |
이미지
|
♥무케♥ | 35 | 3 | |
일기장 |
이미지
|
구내염에는알보칠 | 158 | 5 | |
일기장 |
기본
|
메르시장인 | 63 | 9 | |
일기장 |
기본
|
메르시장인 | 58 | 8 | |
일기장 |
이미지
|
정진솔 | 31 | 3 | |
일기장 |
이미지
|
정진솔 | 64 | 7 | |
일기장 |
기본
|
육상천재방예나 | 62 | 5 | |
일기장 |
기본
|
메르시장인 | 80 | 10 |