Skip to content

Instantly share code, notes, and snippets.

@marharyta
Last active August 10, 2018 15:35
Show Gist options
  • Save marharyta/3e1ea2f05a168eaf65a96571145e2780 to your computer and use it in GitHub Desktop.
Save marharyta/3e1ea2f05a168eaf65a96571145e2780 to your computer and use it in GitHub Desktop.
React-redux-search index.js with React state
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