質問編集履歴
1
例のコードを追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,9 +22,119 @@
|
|
22
22
|
|
23
23
|
|
24
24
|
|
25
|
+
コード
|
26
|
+
|
27
|
+
* `ListContainer.tsx` の一部
|
28
|
+
|
29
|
+
```
|
30
|
+
|
31
|
+
render(){
|
32
|
+
|
33
|
+
return(
|
34
|
+
|
35
|
+
<div class="ListContainer">
|
36
|
+
|
37
|
+
<h2>動物一覧<h2>
|
38
|
+
|
39
|
+
<AnimalList animalData={jsonData}/>
|
40
|
+
|
41
|
+
</div>
|
42
|
+
|
43
|
+
);
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
* `AnimalList` の一部
|
50
|
+
|
51
|
+
```
|
52
|
+
|
53
|
+
render(){
|
54
|
+
|
55
|
+
let animalNodes = this.props.data.map((animal)=>{
|
56
|
+
|
57
|
+
return (
|
58
|
+
|
59
|
+
<Animal name={animal.name} height={animal.height} weight={animal.weight} />
|
60
|
+
|
61
|
+
);
|
62
|
+
|
63
|
+
});
|
64
|
+
|
65
|
+
return(
|
66
|
+
|
67
|
+
<div class="AnimalList">
|
68
|
+
|
69
|
+
{animalNodes}
|
70
|
+
|
71
|
+
</div>
|
72
|
+
|
73
|
+
);
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
```
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
* `Animal` の一部(ここで押されたボタンの情報(名前・体重・身長)によって別のページに飛ばしたい)
|
82
|
+
|
83
|
+
```
|
84
|
+
|
85
|
+
render() {
|
86
|
+
|
87
|
+
return (
|
88
|
+
|
89
|
+
<div className="animal">
|
90
|
+
|
91
|
+
<a className="animalName">
|
92
|
+
|
93
|
+
{this.props.name}
|
94
|
+
|
95
|
+
</a>
|
96
|
+
|
97
|
+
</div>
|
98
|
+
|
99
|
+
);
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
```
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
* `AnimalInformation` の一部(ここでどのようにAnimalの情報を持ってくればよいのか分からない)
|
108
|
+
|
109
|
+
```
|
110
|
+
|
111
|
+
render() {
|
112
|
+
|
113
|
+
return(
|
114
|
+
|
115
|
+
<div className="AnimalInformation">
|
116
|
+
|
117
|
+
<h2>押したボタンの動物の名前をここに表示する</h2>
|
118
|
+
|
119
|
+
<p>押したボタンの動物の体重をここに表示する</p>
|
120
|
+
|
121
|
+
<p>押したボタンの動物の身長をここに表示する</p>
|
122
|
+
|
123
|
+
</div>
|
124
|
+
|
125
|
+
);
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
```
|
130
|
+
|
131
|
+
|
132
|
+
|
25
133
|
というような4つのコンポーネントがあったとして、
|
26
134
|
|
27
135
|
<Animal>ボタンで押された動物の情報(名前・体重・身長)を<AnimalInformation />に渡すにはどのような方法で実装すればよいのでしょうか?
|
136
|
+
|
137
|
+
|
28
138
|
|
29
139
|
親子関係ならばPropやStateで値を受け渡しできると思うのですが...
|
30
140
|
|