Last active
August 10, 2018 15:35
-
-
Save marharyta/3e1ea2f05a168eaf65a96571145e2780 to your computer and use it in GitHub Desktop.
React-redux-search index.js with React state
This file contains 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 ReactDOM from 'react-dom'; | |
import styled from 'styled-components'; | |
import './css/main.css'; | |
class App extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { coworkings: [] }; | |
} | |
componentDidMount() { | |
fetch('https://api.myjson.com/bins/nwxou', { | |
headers: { | |
Accept: 'application/json', | |
'Content-Type': 'application/json' | |
} | |
}) | |
.then(res => res.json()) | |
.then(res => { | |
console.log(res); | |
this.setState({ coworkings: res.coworkings }); | |
return res.coworkings; | |
}) | |
.catch(error => { | |
console.log(error); | |
}); | |
} | |
render() { | |
return ( | |
<ul className={this.props.className}> | |
{this.state.coworkings.map(i => { | |
return ( | |
<li key={i.id}> | |
<h2> {i.title} </h2> | |
<p> website: {i.website}</p> | |
<div> | |
{i.address.map(a => { | |
return ( | |
<p key={a.id}> | |
<img | |
src={`https://maps.googleapis.com/maps/api/streetview?size=600x300&location=${ | |
i.address[0].lat | |
},${ | |
i.address[0].lng | |
}&key=AIzaSyA16d9FJFh__vK04jU1P64vnEpPc3jenec`} | |
alt={'alt'} | |
/> | |
{`address ${a.street}, ${a.postcode}, ${a.city}, ${ | |
a.country | |
} `} | |
</p> | |
); | |
})} | |
</div> | |
</li> | |
); | |
})} | |
</ul> | |
); | |
} | |
} | |
const StyledApp = styled(App)` | |
color: palevioletred; | |
font-weight: bold; | |
`; | |
const rootElement = document.getElementById('root'); | |
ReactDOM.render(<StyledApp />, rootElement); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment