Created
May 22, 2018 15:15
-
-
Save danjordan/0a9000a4ef9579953da041ed6b774fd8 to your computer and use it in GitHub Desktop.
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
const axios = require('axios'); | |
export const getItems = () => axios.get('/api/items'); |
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
const React = require('react'); | |
const getItems = require('./api').getItems; | |
class ItemsList extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
items: [] | |
} | |
} | |
componentDidMount() { | |
getItems().then(response => { | |
const items = response.data; | |
this.setState({ items }); | |
}); | |
} | |
componentWillUnmount() { | |
// cancel request | |
} | |
render() { | |
// render items | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment