https://img.youtube.com/vi/snBvYS6eC2E/mqdefault.jpg 이전글 [**"\[React Native\] MobX State Tree 학습하기 #1"**](/zzan/@anpigon/react-native-mobx-state-tree-1) 에서 이어지는 내용입니다. ___ 본 포스팅은 아래 강의를 보면서 정리한 노트입니다. https://www.youtube.com/watch?v=snBvYS6eC2E ___ <br><br> # BookStore에 초기 데이터 등록하기 `BookStore.js` 파일을 수정합니다. `books` 배열에 다음과 같이 Book 정보를 입력합니다. 이제 **BookStore**는 book 데이터 하나를 가지고 생성됩니다. ```js const BookStore = types .model('Books', { books: types.array(Book), }) .create({ books: [ // book 정보 등록 { title: 'Ready Player One', author: 'Ernest Cline', read: true, }, ], }); ``` <br> 이제 앱을 실행하고 **Console** 에서 값을 확인해봅니다. `Target`의 첫번째 항목을 살펴보면, `value`에 우리가 입력한 Book 데이터가 보입니다.  *** <br> <br> # BookStore에 addBook 액션(action) 추가하기 다시 `BookStore.js` 파일을 수정합니다. 그리고 actions에 `addBook` 함수를 추가합니다. actions에는 store에서만 호출할 수 있는 private 함수를 생성 할 수 있습니다. 이제 **BookStore**의 `addBook` 함수를 호출하면 `books` 배열에 새로운 book 객체가 추가됩니다. ```js const BookStore = types .model('Books', { books: types.array(Book), }) // actions 추가 .actions(self => ({ addBook(book) { self.books.push(book); }, })) .create({ books: [ { title: 'Ready Player One', author: 'Ernest Cline', read: true, }, ], // 초기 값 }); ``` <br> <br> # 입력 화면 만들기 `App.js` 파일을 수정합니다. 그리고 **react-native**에서 `StyleSheet`, `SafeAreaView`, `TextInput`, `Text`, `Button` 컴포넌트를 **import** 합니다. ```js import { SafeAreaView, StyleSheet, TextInput, Text, Button } from 'react-native'; ``` <br>그리고 `initialState` 값을 설정합니다. **initialState**는 `title`와 `author` 속성을 가집니다. ```js const initialState = { title: '', author: '' }; ``` <br>그다음 `state`를 생성합니다. `state`의 기본값으로는 `initialState` 를 입력합니다. 그리고 `onChangeText` 함수와 `addBook` 함수를 생성합니다. ```js class App extends React.Component { state = initialState; // TextInput 입력 이벤트 함수 onChangeText = (key, value) => { this.setState({ [key]: value, }); }; // book 추가하기 함수 addBook = () => { BookStore.addBook(this.state); this.setState(initialState); }; ... ``` <br>그 다음 화면 UI에 적용할 **StyleSheet**를 정의합니다. `<TextInput>` 컴포넌트의 높이는 50, 배경색은 회색 그리고 위아래 여백으로 10을 주었습니다. ```js const styles = StyleSheet.create({ input: { height: 50, backgroundColor: '#ededed', marginVertical: 10, }, }); ``` <br>그리고 화면에 보여줄 입력 박스(TextInput) 2개와 버튼을 입력합니다. 첫번째 TextInput는 제목(title)를 입력받습니다. 두번째 TextInput는 저자(author)를 입력받습니다. ```js class App extends React.Component { ... render() { return ( <SafeAreaView> <TextInput style={styles.input} value={this.state.title} onChangeText={value => this.onChangeText('title', value)} /> <TextInput style={styles.input} value={this.state.author} onChangeText={value => this.onChangeText('author', value)} /> <Button title="Add Book" onPress={this.addBook} /> </SafeAreaView> ); }; ``` <br> <br> # MobX observer 클래스 등록하기 **mobx-react**에서 `observer`를 **import**합니다. 그리고 대상 클래스 바로 위에 어노테이션 `@observer`를 입력합니다. ```js import { observer } from 'mobx-react'; @observer class App extends React.Component { ... ``` <br> 그리고 다음은 지금까지 구현한 전체 소스코드입니다.  <br> 아래는 결과 화면입니다. 제목과 저자를 입력하고 Add Book를 누르면 아래에 추가된 정보가 표시됩니다. ||| |-|-| ||| *** <br> `댓글`, `팔로우`, `좋아요` 해 주시는 모든 분께 감사합니다. 항상 행복한 하루 보내시길 바랍니다. *** <center><img src='https://steemitimages.com/400x0/https://cdn.steemitimages.com/DQmQmWhMN6zNrLmKJRKhvSScEgWZmpb8zCeE2Gray1krbv6/BC054B6E-6F73-46D0-88E4-C88EB8167037.jpeg'><h5>vote, reblog, follow <code><a href='/@anpigon'>@anpigon</a></code></h5></center> <br>
author | anpigon |
---|---|
permlink | react-native-mobx-state-tree-2 |
category | zzan |
json_metadata | {"app":"steemzzang/0.1","format":"markdown","tags":["zzan","kr-dev","liv","palnet","neoxian","sct","sct-freeboard","react-native","busy","jjm"],"links":["/zzan/@anpigon/react-native-mobx-state-tree-1","https://www.youtube.com/watch?v=snBvYS6eC2E","/@anpigon"],"image":["https://img.youtube.com/vi/snBvYS6eC2E/mqdefault.jpg","https://img.youtube.com/vi/snBvYS6eC2E/0.jpg","https://files.steempeak.com/file/steempeak/anpigon/BXbsbUny-1.png","https://files.steempeak.com/file/steempeak/anpigon/68pMhQTV-carbon.png","https://steemitimages.com/740x0/https://files.steempeak.com/file/steempeak/anpigon/D6iI217Y-E18489E185B3E1848FE185B3E18485E185B5E186ABE18489E185A3E186BA202019-08-1120E1848BE185A9E18492E185AE206.53.13.png","https://files.steempeak.com/file/steempeak/anpigon/EuSXwg0u-2019-08-112022-19-47.2019-08-112022_21_27.gif","https://steemitimages.com/400x0/https://cdn.steemitimages.com/DQmQmWhMN6zNrLmKJRKhvSScEgWZmpb8zCeE2Gray1krbv6/BC054B6E-6F73-46D0-88E4-C88EB8167037.jpeg"]} |
created | 2019-08-12 13:25:48 |
last_update | 2019-08-28 22:34:09 |
depth | 0 |
children | 8 |
last_payout | 2019-08-19 13:25:48 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.617 HBD |
curator_payout_value | 0.168 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 4,178 |
author_reputation | 17,258,940,000,931 |
root_title | "[React Native] MobX State Tree 학습하기 #2" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 89,438,930 |
net_rshares | 2,394,830,700,551 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
bert0 | 0 | 1,214,299,470 | 0.4% | ||
leduc1984 | 0 | 49,142,629 | 80% | ||
guest123 | 0 | 876,733,122 | 100% | ||
skan | 0 | 306,592,090,901 | 100% | ||
sisilafamille | 0 | 578,032,990 | 100% | ||
happyberrysboy | 0 | 19,136,112,942 | 100% | ||
hellosteem | 0 | 789,076,674 | 100% | ||
stylegold | 0 | 473,703,765 | 100% | ||
virus707 | 0 | 246,360,725,755 | 1% | ||
realmankwon | 0 | 6,449,230,917 | 25% | ||
everrich | 0 | 107,158,030 | 12% | ||
forhappywomen | 0 | 47,915,598,733 | 100% | ||
accelerator | 0 | 16,935,006,212 | 0.54% | ||
krfeed | 0 | 279,085,543 | 100% | ||
pediatrics | 0 | 7,924,772,647 | 25% | ||
yjs3694 | 0 | 73,689,350,582 | 100% | ||
eversloth | 0 | 348,935,090,492 | 100% | ||
philhyuntd | 0 | 2,019,239,108 | 50% | ||
sargoon | 0 | 143,035,445 | 1.66% | ||
songbj | 0 | 1,297,819,109 | 100% | ||
wonsama | 0 | 29,522,857,069 | 100% | ||
tanky | 0 | 11,526,895,147 | 100% | ||
steem.apps | 0 | 4,213,364,583 | 25% | ||
blockchainstudio | 0 | 215,564,438,697 | 100% | ||
anpigon | 0 | 11,819,317,720 | 100% | ||
newbijohn | 0 | 17,642,383,890 | 50% | ||
ulockblock | 0 | 172,065,461,705 | 100% | ||
china.mobile | 0 | 1,057,707,834 | 20% | ||
laissez-faire | 0 | 13,298,301 | 100% | ||
steem-ua | 0 | 164,617,648,009 | 3.32% | ||
gomdory | 0 | 96,669,426,829 | 100% | ||
talken | 0 | 934,579,441 | 100% | ||
steemory | 0 | 3,612,937,010 | 100% | ||
pigoncchio | 0 | 693,661,336 | 100% | ||
maeil | 0 | 0 | 100% | ||
coredump | 0 | 27,990,623 | 25% | ||
stpeople | 0 | 455,087,612,171 | 7.97% | ||
roadofrich | 0 | 118,035,826,485 | 1.38% | ||
wangpigon | 0 | 1,233,057,142 | 100% | ||
map10k | 0 | 1,642,874,870 | 0.55% | ||
sct.jcob | 0 | 1,365,587,366 | 100% | ||
wonsama.sct | 0 | 1,682,509,540 | 100% | ||
nympheas | 0 | 397,006,769 | 100% | ||
zzan.adv | 0 | 417,220,326 | 25% | ||
zzan.co7 | 0 | 114,704,122 | 50% | ||
zzan.co10 | 0 | 151,178,545 | 50% | ||
kudock | 0 | 315,765,055 | 100% | ||
realmankwon.scot | 0 | 1,200,358,270 | 100% | ||
gghite.zzan | 0 | 1,439,726,630 | 100% |
#### Hi @anpigon! Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation! Your **UA** account score is currently 3.420 which ranks you at **#7424** across all Steem accounts. Your rank has not changed in the last three days. In our last Algorithmic Curation Round, consisting of 157 contributions, your post is ranked at **#77**. ##### Evaluation of your UA score: * You're on the right track, try to gather more followers. * The readers like your work! * You have already shown user engagement, try to improve it further. **Feel free to join our [@steem-ua Discord server](https://discord.gg/KpBNYGz)**
author | steem-ua |
---|---|
permlink | re-react-native-mobx-state-tree-2-20190816t060006z |
category | zzan |
json_metadata | "{"app": "beem/0.20.23"}" |
created | 2019-08-16 06:00:09 |
last_update | 2019-08-16 06:00:09 |
depth | 1 |
children | 0 |
last_payout | 2019-08-23 06:00:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 655 |
author_reputation | 23,214,230,978,060 |
root_title | "[React Native] MobX State Tree 학습하기 #2" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 89,585,625 |
net_rshares | 0 |
 [kr-newbie](/@kr-newbie)님이 anpigon님을 멘션하셨습니당. 아래 링크를 누르시면 연결되용~ ^^ <br />[kr-newbie](/@kr-newbie)님의 [[8/12 kr-newbie 큐레이팅 프로젝트]](/zzan/@kr-newbie/8-12-kr-newbie) <br /> <blockquote>...b.io/#/wallet/kr-newbie happigon에서 자세한 임대내역이 확인 가능합니다. 만들어주신 anpigon께 감사드립니다! anpigon님의 HAAPIGON 유저가이드를 참고해주시기 바랍니다! <br> <...</blockquote>
author | steem.apps |
---|---|
permlink | re---------react-native-mobx-state-tree-2-20190812t152809175z |
category | zzan |
json_metadata | {"app":"steem.apps/0.1","format":"markdown"} |
created | 2019-08-12 15:28:09 |
last_update | 2019-08-12 15:28:09 |
depth | 1 |
children | 0 |
last_payout | 2019-08-19 15:28:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 414 |
author_reputation | 7,218,006,883,278 |
root_title | "[React Native] MobX State Tree 학습하기 #2" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 89,443,411 |
net_rshares | 0 |
 [sct.notice](/@sct.notice)님이 anpigon님을 멘션하셨습니당. 아래 링크를 누르시면 연결되용~ ^^ <br />[kr-newbie](/@kr-newbie)님의 [[8/12 kr-newbie 큐레이팅 프로젝트]](/zzan/@kr-newbie/8-12-kr-newbie#@sct.notice/re-kr-newbie-8-14521) <br /> <blockquote><ul> <i>태그 작성 가이드라인 준수는 콘텐츠 관리와 글에 대한 접근성을 높이기 위해 반드시 필요한 절차입니다. </li> <li>스팀코인판에서 활용 가능한 태그는 크게 [보상태그 / 언어태그/ 주제태그]로 구분할 수 있습...</blockquote>
author | steem.apps |
---|---|
permlink | re---------react-native-mobx-state-tree-2-20190812t153033273z |
category | zzan |
json_metadata | {"app":"steem.apps/0.1","format":"markdown"} |
created | 2019-08-12 15:30:33 |
last_update | 2019-08-12 15:30:33 |
depth | 1 |
children | 0 |
last_payout | 2019-08-19 15:30:33 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 446 |
author_reputation | 7,218,006,883,278 |
root_title | "[React Native] MobX State Tree 학습하기 #2" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 89,443,508 |
net_rshares | 0 |
 [wonsama.zzan](/@wonsama.zzan)님이 anpigon님을 멘션하셨습니당. 아래 링크를 누르시면 연결되용~ ^^ <br />[wonsama.zzan](/@wonsama.zzan)님의 [[ZZAN] DAILY REPORT 2019.08.12](/zzan/@wonsama.zzan/zzan-daily-report-2019-08-12) <br /> <blockquote>...<td>[댓글이벤트]감사&하루노트 - #00</td> <td>12</td> </tr> <tr> <td>anpigon/td> <td>22:25:48</td> <td>[React Native] MobX </td> <td>13</...</blockquote>
author | steem.apps |
---|---|
permlink | re---------react-native-mobx-state-tree-2-20190812t154047872z |
category | zzan |
json_metadata | {"app":"steem.apps/0.1","format":"markdown"} |
created | 2019-08-12 15:40:48 |
last_update | 2019-08-12 15:40:48 |
depth | 1 |
children | 0 |
last_payout | 2019-08-19 15:40:48 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 450 |
author_reputation | 7,218,006,883,278 |
root_title | "[React Native] MobX State Tree 학습하기 #2" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 89,443,974 |
net_rshares | 0 |
 [wonsama](/@wonsama)님이 anpigon님을 멘션하셨습니당. 아래 링크를 누르시면 연결되용~ ^^ <br />[wonsama](/@wonsama)님의 [이벤트) 제4회 제목학원 with 알라딘](/zzan/@wonsama/4-with) <br /> <blockquote>...o8, floridasnail, ioioioioi, untold, kiwifi, goodhello, jjy, anpigon kibumh, asd5710, chosk 맺음말<ul> <li>많은 참여 바랍니다.</li> </ul> </blockquote>
author | steem.apps |
---|---|
permlink | re---------react-native-mobx-state-tree-2-20190812t161151061z |
category | zzan |
json_metadata | {"app":"steem.apps/0.1","format":"markdown"} |
created | 2019-08-12 16:11:51 |
last_update | 2019-08-12 16:11:51 |
depth | 1 |
children | 0 |
last_payout | 2019-08-19 16:11:51 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 386 |
author_reputation | 7,218,006,883,278 |
root_title | "[React Native] MobX State Tree 학습하기 #2" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 89,444,994 |
net_rshares | 0 |
 [floridasnail](/@floridasnail)님이 anpigon님을 멘션하셨습니당. 아래 링크를 누르시면 연결되용~ ^^ <br />[floridasnail](/@floridasnail)님의 [[나의 스팀엔진 이야기] 이번엔 주물주 위에 건물주, 건물주 위에 스엔주 (스팀 엔진 토큰과 그 임대풀) - Aug '19](/zzan/@floridasnail/aug-19) <br /> <blockquote>... 한번 비교해보려고 합니다.지난 달에 스팀엔진에서는 토큰의 임대 내역을 알수 없다고 말씀드렸었는데요, 이제는 anpigon님이 만들어주신 https://happigon.github.io/#/wallet 에서 각 토큰의 임대 내역을 ...</blockquote>
author | steem.apps |
---|---|
permlink | re---------react-native-mobx-state-tree-2-20190813t220211997z |
category | zzan |
json_metadata | {"app":"steem.apps/0.1","format":"markdown"} |
created | 2019-08-13 22:02:12 |
last_update | 2019-08-13 22:02:12 |
depth | 1 |
children | 0 |
last_payout | 2019-08-20 22:02:12 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 466 |
author_reputation | 7,218,006,883,278 |
root_title | "[React Native] MobX State Tree 학습하기 #2" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 89,493,260 |
net_rshares | 4,192,147,156 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
steem.apps | 0 | 4,192,147,156 | 25% |
Congratulations @anpigon! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) : <table><tr><td><img src="https://steemitimages.com/60x70/http://steemitboard.com/@anpigon/voted.png?201908121350"></td><td>You received more than 15000 upvotes. Your next target is to reach 20000 upvotes.</td></tr> </table> <sub>_You can view [your badges on your Steem Board](https://steemitboard.com/@anpigon) and compare to others on the [Steem Ranking](https://steemitboard.com/ranking/index.php?name=anpigon)_</sub> <sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub> ###### [Vote for @Steemitboard as a witness](https://v2.steemconnect.com/sign/account-witness-vote?witness=steemitboard&approve=1) to get one more award and increased upvotes!
author | steemitboard |
---|---|
permlink | steemitboard-notify-anpigon-20190812t151532000z |
category | zzan |
json_metadata | {"image":["https://steemitboard.com/img/notify.png"]} |
created | 2019-08-12 15:15:33 |
last_update | 2019-08-12 15:15:33 |
depth | 1 |
children | 0 |
last_payout | 2019-08-19 15:15:33 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 843 |
author_reputation | 38,975,615,169,260 |
root_title | "[React Native] MobX State Tree 학습하기 #2" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 89,442,914 |
net_rshares | 0 |
Thank you for your continued support towards JJM. For each 1000 JJM you are holding, you can get an additional 1% of upvote. 10,000JJM would give you a 11% daily voting from the 700K SP virus707 account.
author | virus707 |
---|---|
permlink | re-react-native-mobx-state-tree-2-1565620352 |
category | zzan |
json_metadata | {"tags":["jjm"]} |
created | 2019-08-12 14:32:30 |
last_update | 2019-08-12 14:32:30 |
depth | 1 |
children | 0 |
last_payout | 2019-08-19 14:32:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 203 |
author_reputation | 557,563,606,581,756 |
root_title | "[React Native] MobX State Tree 학습하기 #2" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 89,441,186 |
net_rshares | 0 |