-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathStateExampleCode.js
More file actions
executable file
·40 lines (35 loc) · 926 Bytes
/
Copy pathStateExampleCode.js
File metadata and controls
executable file
·40 lines (35 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React, { Component, Fragment } from 'react';
class App extends Component {
state = {
cityArray1: ["Karachi", "Lahore", "Peshawer", "Quetta"],
cityArray2: ["Hyderabad", "Multan", "Gawader", "Mardan"]
}
render() {
return (
//You can also use <div> instead of <Fragment>
<Fragment>
<City cityArray={this.state.cityArray1} name="Aamir" />
<City cityArray={this.state.cityArray2} name="Pinger" />
</Fragment>
)
}
}
class City extends Component {
render() {
const cityArray = this.props.cityArray
// you can also do like this
//const { cityArray } = this.props
return (
//You can also use <div> instead of <Fragment>
<Fragment>
<ul>
{
cityArray.map((city) => <li key={city}> {city} </li>)
}
</ul>
<h4> {this.props.name} </h4>
</Fragment>
)
}
}
export default App;