Skip to content

Instantly share code, notes, and snippets.

@manuel-mauky
Last active June 15, 2020 18:19
Show Gist options
  • Save manuel-mauky/5fad238f1a4e1991aa6a808a8a477b05 to your computer and use it in GitHub Desktop.
Save manuel-mauky/5fad238f1a4e1991aa6a808a8a477b05 to your computer and use it in GitHub Desktop.
React-Hooks-Article: Load data in class component
import React from "react"
export class LoadDataClass extends React.Component {
componentDidMount(): void {
fetch("/some-data.json")
.then((response) => response.json())
.then((data) => {
this.setState({ data })
})
}
render() {
return (
<div>
{this.state.data.map((item) => (
<p>{item}</p>
))}
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment