Last active
April 18, 2018 01:48
-
-
Save colorfield/5448814c58d05138f6862d975a3108ec to your computer and use it in GitHub Desktop.
AudioGuide Demo - fetch componentDidMount
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
(...) | |
constructor() { | |
super(); | |
this.state = { | |
audioList: { data: [] }, | |
}; | |
} | |
componentDidMount() { | |
const { locale, content } = this.props; | |
this.state.locale = locale; | |
const drupalLocale = this.state.locale.substring(0, 2); | |
const guideEndpoint = `${restHostName}/jsonapi/node/audio?sort=title&filter[langcode][value]=${drupalLocale}`; | |
fetch(guideEndpoint) | |
.then(response => response.json()) | |
.then(audioList => this.setState({ audioList })); | |
} | |
render() { | |
return ( | |
<div className={s.root}> | |
<div className={s.container}> | |
<div> | |
<ul> | |
{this.state.audioList.data.map( | |
audioItem => | |
(<li key={audioItem.attributes.uuid}> | |
<Link className={s.link} to={`/audio/${audioItem.attributes.uuid}`}> | |
{audioItem.attributes.title} | |
</Link> | |
</li>), | |
)} | |
</ul> | |
</div> | |
</div> | |
</div> | |
); | |
(...) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment