私は現在自分自身を教えようとしていますReact、私は現時点でcodepenで働いていますが、私がやっていることは静的なJSONから簡単なユーザープロファイルを作成することです。概念のリアクションの証明
私が誰かから欲しいのは、進歩する前に私の理解が正しいことを確認することです。
Reactアプリは状態オブジェクトによって駆動されると私は理解していますか?この状態オブジェクトの要素はコンポーネントに渡すことができ、それらは小道具(読み込み専用ですか?)になります。私が状態にあることができれば、コンポーネント内で使用されているどの小道具にも反映されますか?
基本的に状態からアバターURLを取得し、非常に単純なアバターコンポーネントを作成することは、これまでのところ私の立証したことです。
/*
* A simple React component
*/
const user = {
"id": 1,
"first_name": "Anjela",
"last_name": "Frow",
"email": "[email protected]",
"dob": "1987-07-09",
"gender": "Female",
"avatar": "https://robohash.org/quaslaboriosamvoluptas.jpg?size=50x50&set=set1"
}
class Application extends React.Component {
constructor() {
super();
this.state = {
user:user
}
}
render() {
return (<Profile user={this.state.user} />);
}
}
class Profile extends React.Component {
render() {
return (
<Avatar image={this.props.user.avatar} />
)
}
}
class Avatar extends React.Component {
render() {
return (
<div class="avatar">
<img src={this.props.image} />
</div>
)
}
}
/*
* Render the above component into the div#app
*/
React.render(<Application />, document.getElementById('app'));
https://codepen.io/87Development/pen/XabxGX?editors=1010
[** DOC **](https://facebook.github.io/react/docs/hello-world.html)を確認するようおすすめしますが、詳細についてはすべて説明します。 –
これはcodereviewの質問ではないでしょうか?反応は、州または小道具のいずれかによって駆動されることができます。それは、あなたが仮定しているところで正しいです。 – Icepickle
はい。あなたの理解は正しいです。状態を他のコンポーネントに渡すことができ、親コンポーネントの状態を更新する場合にのみその小道具を更新します –