Created
April 10, 2019 20:10
-
-
Save noili/6e09114ec8541a6628328a6acbc8d203 to your computer and use it in GitHub Desktop.
React practice
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, { Component } from 'react'; | |
import './App.css'; | |
import { BrowserRouter as Router, Route } from "react-router-dom"; | |
import SearchBar from './components/SearchBar' | |
import ItemList from './components/ItemList' | |
class App extends Component { | |
state = {items: []} | |
handleSubmit = q => { | |
fetch(`https://api.mercadolibre.com/sites/MLA/search?q=${q}`) | |
.then(results => { | |
return results.json() | |
}).then(data => { | |
console.log(data.results.slice(0, 4)); | |
this.setState({items: data.results.slice(0, 4)}) | |
}); | |
} | |
render() { | |
return ( | |
<div className="App"> | |
<SearchBar handleSubmit={this.handleSubmit} /> | |
<Router> | |
<div> | |
<Route | |
path="/items" | |
render={(props) => <ItemList list={props.list}/>} | |
/> | |
{/* <Route path="/items/:id" component={Item} /> */} | |
</div> | |
</Router> | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment