Created
January 9, 2020 12:35
-
-
Save omas-public/8d334f46af69cdc42aebc56d6cb80739 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react' | |
| import sa from 'superagent' | |
| class App extends React.Component { | |
| constructor (props) { | |
| super(props) | |
| this.state = { items: null } | |
| } | |
| async loadedJSON () { | |
| const getAPI = uri => | |
| window.fetch(uri).then(res => res.json()) | |
| const URI = './fruits.json' | |
| const data = await getAPI(URI) | |
| .then(json => json.fruits) | |
| this.setState({ items: data }) | |
| } | |
| componentDidMount () { | |
| this.loadedJSON() | |
| } | |
| render () { | |
| const items = this.state.items | |
| return ( | |
| <Display items={items} /> | |
| ) | |
| } | |
| } | |
| const Display = props => { | |
| if (!props.items) { | |
| return <div>now loading!</div> | |
| } | |
| const options = props.items.map(item => | |
| <option value={item.price} key={item.name}> | |
| {item.name} | |
| </option> | |
| ) | |
| return ( | |
| <label>fruite | |
| <select>{options}</select> | |
| </label> | |
| ) | |
| } | |
| export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment