-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathPropTypeInClass.js
executable file
·45 lines (34 loc) · 1.05 KB
/
PropTypeInClass.js
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
40
41
42
43
44
45
import React from 'react'
import PropType from 'prop-types'
class MyComponent extends React.Component {
static propTypes = {
cityArray: PropType.array.isRequired
}
render () {
const cityArray = this.props.cityArray
const shortListedCities = cityArray.filter(city => city.length > 6)
// this.props.myFunction()
return (
<ul>
{shortListedCities.map(city => <li key={city}> {city} </li>)}
</ul>
)
}
}
function MyFunctionalComponent (props) {
return <h1>{props.heading}</h1>
}
function App () {
const cityArray1 = ['Karachi', 'Lahore', 'Peshawar', 'Quetta']
const cityArray2 = ['Hyderabad', 'Islamabad', 'Sawat', 'Gawader']
const cityObj = { city1: 'Karachi', city2: 'Lahore', city3: 'Peshawar', city4: 'Quetta' }
const myFunction = () => alert('Hello World')
return (
<div>
<MyFunctionalComponent heading='Cities List' />
<MyComponent cityArray={cityObj} myFunction={myFunction} />
<MyComponent cityArray={cityArray2} myFunction={myFunction} />
</div>
)
}
export default App