Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Reading a list of categories from the API in a React component
import React, { Component } from "react";
import config from "./config";
import CategoriesList from "./CategoriesList";
class Categories extends Component {
constructor(props) {
this.state = {
categories: []
componentWillMount() {
.then(response => response.json())
.then(json => this.setState({ categories: json }))
.catch(() => {
console.log("An error occured");
render() {
return <CategoriesList categories={this.state.categories} />;
export default Categories;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.