Skip to content

Instantly share code, notes, and snippets.

@olvap
Forked from noili/App.js
Created April 10, 2019 20:11
Show Gist options
  • Save olvap/9bd56d54f73ce8a359083573803c7032 to your computer and use it in GitHub Desktop.
Save olvap/9bd56d54f73ce8a359083573803c7032 to your computer and use it in GitHub Desktop.
React practice
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