create account

[React] Mobx-state-tree 학습하기 #8 : Create an Entry Form to Add Models to the State Tree by anpigon

View this thread on: hive.blogpeakd.comecency.com
· @anpigon · (edited)
$1.22
[React] Mobx-state-tree 학습하기 #8 : Create an Entry Form to Add Models to the State Tree
이전글 [**"\[React\] Mobx-state-tree 학습하기 #7 : Remove Model Instances from the Tree"**](/zzan/@anpigon/react-native-manage-application-state-with-mobx-state-tree-7)에서 이어지는 내용입니다. 참고로 이 포스팅은 제가 학습한 내용을 노트에 정리하듯이 기록하여 올리는 글이기 때문에 보팅 안해주셔서 됩니다.  많은 분들이 코딩에 흥미를  느꼈으면 좋겠습니다.  ㅋ

<br>

***

![](https://files.steempeak.com/file/steempeak/anpigon/sYISPibs-E1848CE185A6E18486E185A9E186A820E1848BE185A5E186B9E18482E185B3E186AB20E18483E185B5E1848CE185A1E1848BE185B5E186AB.png)
* 출처: https://egghead.io/courses/manage-application-state-with-mobx-state-tree

***

<br>

## Create an Entry Form to Add Models to the State Tree

* 강의 링크: https://egghead.io/lessons/react-create-an-entry-form-to-add-models-to-the-state-tree
<br>8번째 레슨입니다. 위시 리스트에 새 항목을 추가 할 시간입니다. 우리는 지금까지 작성한 입력폼과 모델을 재사용할 것입니다.

<br>우리는 다음을 배우게 됩니다.

*  MST는 단일 상태 트리(single state tree)로 제한되지 않습니다. 모든 모델은 자체적인 트리를 가질 수 있습니다
* 상태 트리(state tree)에 모델 인스턴스 추가하기
<br>

***


<br><br>

새 파일 `WishListItemEntry.js`을 생성합니다. 여기서 **WishListItemEdit** 컴포넌트를 재활용합니다. 그리고 Add 버튼을 만들었습니다. 입력양식을 작성하고 Add 버튼을 누르면 WishList 모델에 새 항목을 추가하게 됩니다.

`src/components/WishListItemEntry.js`
```
import React, { Component } from "react";
import { observer } from "mobx-react";

import WishListItemEdit from "./WishListItemEdit";

import { WishListItem, WishList } from "../models/WhishList";

class WishListItemEntry extends Component {
  constructor() {
    super();
    this.state = {
      entry: WishListItem.create({
        name: "",
        price: 0
      })
    };
  }

  render() {
    return (
      <div>
        <WishListItemEdit item={this.state.entry} />
        <button onClick={this.onAdd}>Add</button>
      </div>
    );
  }

  onAdd = () => {
    this.props.wishList.add(this.state.entry);
    this.setState({
      entry: WishListItem.create({
        name: "",
        price: 0
      })
    });
  };
}

export default WishListItemEntry;

```

<br><br>

그다음 `WishListView.js` 파일을 수정합니다. **WishListView** 컴포넌트에는 방금 만든 **WishListItemEntry** 컴포넌트를 추가하여 화면에 보여줍니다.

`src/components/WishListView.js`
```
import React from "react";
import { observer } from "mobx-react";
import WishListItemView from "./WishListItemView";
import WishListItemEntry from './WishListItemEntry'; // add here

const WishListView = ({ wishList }) => (
  <div className="list">
    <ul>
      {wishList.items.map((item, idx) => (
        <WishListItemView key={idx} item={item} />
      ))}
    </ul>
   Total: {wishList.totalPrice} 💲
   <WishListItemEntry wishList={wishList} />
  </div>
);

export default observer(WishListView);
```

<br>
<br>

**실행화면**

이제 새로운 항목을 작성하고 Add 버튼을 눌러보세요.

***
![](https://files.steempeak.com/file/steempeak/anpigon/fGBLZ36K-2019-08-252017-12-49.2019-08-252017_13_29.gif)
***

<br>오늘 수업 끝.

<br>
<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>

***
<center><sup>Originally posted on [안피곤님의 블로그](http://anpigon.dblog.org/react-mobx-state-tree-8-create-an-entry-form-to-add-models-to-the-state-tree). Steem blog powered by [ENGRAVE](https://engrave.website).</sup></center>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 34 others
properties (23)
authoranpigon
permlinkreact-mobx-state-tree-8-create-an-entry-form-to-add-models-to-the-state-tree
categoryzzan
json_metadata{"format":"markdown","app":"engrave","tags":["zzan","kr","kr-dev","dev"],"image":["https://files.steempeak.com/file/steempeak/anpigon/sYISPibs-E1848CE185A6E18486E185A9E186A820E1848BE185A5E186B9E18482E185B3E186AB20E18483E185B5E1848CE185A1E1848BE185B5E186AB.png","https://files.steempeak.com/file/steempeak/anpigon/sYISPibs-E1848CE185A6E18486E185A9E186A820E1848BE185A5E186B9E18482E185B3E186AB20E18483E185B5E1848CE185A1E1848BE185B5E186AB.png","https://files.steempeak.com/file/steempeak/anpigon/fGBLZ36K-2019-08-252017-12-49.2019-08-252017_13_29.gif"],"links":["https://egghead.io/courses/manage-application-state-with-mobx-state-tree","https://egghead.io/lessons/react-create-an-entry-form-to-add-models-to-the-state-tree","https://steemitimages.com/400x0/https://cdn.steemitimages.com/DQmQmWhMN6zNrLmKJRKhvSScEgWZmpb8zCeE2Gray1krbv6/BC054B6E-6F73-46D0-88E4-C88EB8167037.jpeg'%3E%3Ch5%3Evote,"],"users":["@anpigon"],"engrave":{"domain":"anpigon.dblog.org","permlink":"react-mobx-state-tree-8-create-an-entry-form-to-add-models-to-the-state-tree","url":"https://anpigon.dblog.org/react-mobx-state-tree-8-create-an-entry-form-to-add-models-to-the-state-tree","featured_image":"https://files.steempeak.com/file/steempeak/anpigon/sYISPibs-E1848CE185A6E18486E185A9E186A820E1848BE185A5E186B9E18482E185B3E186AB20E18483E185B5E1848CE185A1E1848BE185B5E186AB.png","categories":["5d8b1dc94302ae00124415b9"]}}
created2019-08-26 02:57:03
last_update2019-09-30 14:34:36
depth0
children6
last_payout2019-09-02 06:26:42
cashout_time1969-12-31 23:59:59
total_payout_value0.653 HBD
curator_payout_value0.568 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,305
author_reputation17,258,940,000,931
root_title"[React] Mobx-state-tree 학습하기 #8 : Create an Entry Form to Add Models to the State Tree"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id89,954,775
net_rshares4,740,891,693,955
author_curate_reward""
vote details (98)
@steem-ua ·
#### 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 115 contributions, your post is ranked at **#20**.
##### Evaluation of your UA score:

* You're on the right track, try to gather more followers.
* The readers like your work!
* Great user engagement! You rock!


**Feel free to join our [@steem-ua Discord server](https://discord.gg/KpBNYGz)**
properties (22)
authorsteem-ua
permlinkre-react-mobx-state-tree-8-create-an-entry-form-to-add-models-to-the-state-tree-20190828t122941z
categoryzzan
json_metadata"{"app": "beem/0.21.0"}"
created2019-08-28 12:29:42
last_update2019-08-28 12:29:42
depth1
children0
last_payout2019-09-04 12:29:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length621
author_reputation23,214,230,978,060
root_title"[React] Mobx-state-tree 학습하기 #8 : Create an Entry Form to Add Models to the State Tree"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id90,033,559
net_rshares0
@steem.apps ·
![](https://steemitimages.com/32x32/https://steemitimages.com/u/kr-newbie/avatar) [kr-newbie](/@kr-newbie)님이 anpigon님을 멘션하셨습니당. 아래 링크를 누르시면 연결되용~ ^^ <br />[kr-newbie](/@kr-newbie)님의 [[8/26 kr-newbie 큐레이팅 프로젝트]](/zzan/@kr-newbie/8-26-kr-newbie) <br /> 

 <blockquote>...b.io/#/wallet/kr-newbie
happigon에서 자세한 임대내역이 확인 가능합니다.
만들어주신 anpigon께 감사드립니다! 
<ul>
<li>anpigon님의 HAAPIGON 유저가이드를 참고해주시기 바랍니다!</...</blockquote>
properties (22)
authorsteem.apps
permlinkre---------react-mobx-state-tree-8-create-an-entry-form-to-add-models-to-the-state-tree-20190826t065439119z
categoryzzan
json_metadata{"app":"steem.apps/0.1","format":"markdown"}
created2019-08-26 06:54:39
last_update2019-08-26 06:54:39
depth1
children0
last_payout2019-09-02 06:54:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length414
author_reputation7,218,006,883,278
root_title"[React] Mobx-state-tree 학습하기 #8 : Create an Entry Form to Add Models to the State Tree"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id89,960,257
net_rshares0
@steemitboard ·
<center>[![](https://steemitimages.com/175x175/http://steemitboard.com/@anpigon/level.png?201908261013)](https://steemitboard.com/@anpigon)
**Congratulations @anpigon**!
You raised your level and are now a **Dolphin**!</center>

###### [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!
properties (22)
authorsteemitboard
permlinksteemitboard-notify-anpigon-20190826t110639000z
categoryzzan
json_metadata{"image":["https://steemitboard.com/img/notify.png"]}
created2019-08-26 11:06:39
last_update2019-08-26 11:06:39
depth1
children0
last_payout2019-09-02 11:06:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length406
author_reputation38,975,615,169,260
root_title"[React] Mobx-state-tree 학습하기 #8 : Create an Entry Form to Add Models to the State Tree"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id89,966,649
net_rshares0
@surpassinggoogle ·
Hi, how are you doing? I have some tasks on Github related to the marlians.com tribe. I wonder if you will have time to take a look and perhaps help to carry it out.
https://github.com/steem-engine-exchange/nitrous/issues/94
https://github.com/steem-engine-exchange/nitrous/issues/98
https://github.com/steem-engine-exchange/nitrous/issues/93

If you need to chat, you can find me here: https://discord.gg/Jjhrej3
properties (22)
authorsurpassinggoogle
permlinkpwuwtk
categoryzzan
json_metadata{"tags":["zzan"],"links":["https://github.com/steem-engine-exchange/nitrous/issues/94","https://github.com/steem-engine-exchange/nitrous/issues/98","https://github.com/steem-engine-exchange/nitrous/issues/93","https://discord.gg/Jjhrej3"],"app":"steemit/0.1"}
created2019-08-26 18:32:09
last_update2019-08-26 18:32:09
depth1
children1
last_payout2019-09-02 18:32:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length413
author_reputation527,661,560,108,742
root_title"[React] Mobx-state-tree 학습하기 #8 : Create an Entry Form to Add Models to the State Tree"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id89,981,269
net_rshares0
@anpigon ·
I'm using Google Translator so it's hard to chat in English. 
So I can't help you much.

but I can help this one.

* https://github.com/steem-engine-exchange/nitrous/issues/93
<br>

Just edit `src/app/components/pages/Grow.js` file 

<br>and add this code 
```
import 'bootstrap/scss/bootstrap.scss'
import 'antd/dist/antd.css'; // or 'antd/dist/antd.less'
```

<br>

like this.

![](https://cdn.steemitimages.com/DQmc2ELdoZvVS9LBH4gsFyenzBigbj46J2EYwhByuad1Ywk/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202019-08-27%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%2012.21.24.png)

<br>

is it right?


![](https://cdn.steemitimages.com/DQmP7DvGka1txMiQvQB5q6k1DF4Hkm1eCyrrsf9A46As1Xu/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202019-08-27%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%2012.25.46.png)
properties (22)
authoranpigon
permlinkpwvlpf
categoryzzan
json_metadata{"tags":["zzan"],"image":["https://cdn.steemitimages.com/DQmc2ELdoZvVS9LBH4gsFyenzBigbj46J2EYwhByuad1Ywk/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202019-08-27%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%2012.21.24.png","https://cdn.steemitimages.com/DQmP7DvGka1txMiQvQB5q6k1DF4Hkm1eCyrrsf9A46As1Xu/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202019-08-27%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%2012.25.46.png"],"links":["https://github.com/steem-engine-exchange/nitrous/issues/93"],"app":"steemzzang/0.1"}
created2019-08-27 03:29:39
last_update2019-08-27 03:29:39
depth2
children0
last_payout2019-09-03 03:29:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length883
author_reputation17,258,940,000,931
root_title"[React] Mobx-state-tree 학습하기 #8 : Create an Entry Form to Add Models to the State Tree"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id89,994,176
net_rshares0
@virus707 ·
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.
properties (22)
authorvirus707
permlinkre-react-mobx-state-tree-8-create-an-entry-form-to-add-models-to-the-state-tree-1566836653
categoryzzan
json_metadata{"tags":["jjm"]}
created2019-08-26 16:24:12
last_update2019-08-26 16:24:12
depth1
children0
last_payout2019-09-02 16:24:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length203
author_reputation557,563,606,581,756
root_title"[React] Mobx-state-tree 학습하기 #8 : Create an Entry Form to Add Models to the State Tree"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id89,977,014
net_rshares0