Skip to content

Instantly share code, notes, and snippets.

@colorfield
Last active April 18, 2018 01:48
Show Gist options
  • Save colorfield/5448814c58d05138f6862d975a3108ec to your computer and use it in GitHub Desktop.
Save colorfield/5448814c58d05138f6862d975a3108ec to your computer and use it in GitHub Desktop.
AudioGuide Demo - fetch componentDidMount
(...)
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