Skip to content

Instantly share code, notes, and snippets.

@joshhunt
Created November 9, 2017 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshhunt/4eb665de27e185b3b173a4089e501adf to your computer and use it in GitHub Desktop.
Save joshhunt/4eb665de27e185b3b173a4089e501adf to your computer and use it in GitHub Desktop.
import 'isomorphic-fetch'; // for older browsers https://caniuse.com/#search=Fetch
import React, { Component } from 'react';
import 'styles.css';
export default class Weapon extends Component {
componentDidMount() {
const options = {
headers: {
'x-api-key': 'abc-123'
}
};
fetch('https://bungie.net/Platform/etc/etc', options)
.then(res => res.json())
.then(data => {
console.log(data.Response.displayProperties.name);
this.setState({ item: data.Response });
});
}
render() {
const { item } = this.state;
// Warning though - React will perform an initial render *before* the API call has
// completed, so item will initially be undefined. Make sure you guard against this
// Maybe like this?
if (!item) {
return <div>Loading...</div>;
}
return (
<div className="weapon">
<div className="header">
<img src="" alt="" />
<h3>Weapon Type</h3>
<h1>{item.displayProperties.name}</h1>
</div>
<div className="statistics">
<img src="" alt="" />
<p>Magazine</p>
<img src="" alt="" />
<p>RPM</p>
</div>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment