How to display different list of items when clicking on a category
<p>I am quite new to React JS and I have this simple UI I need to build. I basically have a list of categories and if I click on a category, a list of items will display under that category. It will hide the list of items if I click on another category.</p>

<p>I was provided two APIs, one containing the JSON of categories and another containing the items.</p>

<p>I have managed to fetch the data from the APIs and spit them out on the DOM. However I am finding it hard to piece the component together to only display the right items when it's category has been clicked.</p>

<p>I am using Babel to transpile my JSX syntax and uses axios to fetch the Data. At the moment my page only spits out all the items and all the categories. Understanding state is difficult for me. </p>

<p>Any advice for a newbie Reactjs leaner? Thanks!</p>

<p>My two APIs can be found in my code since I don't have enough rep points to post links.</p>

<p>My JSX:</p>

<pre><code>var React = require('react');
var ReactDOM = require('react-dom');
var axios = require('axios');



var NavContainer = React.createClass({

  getInitialState: function() {
    return {
      category: [],
      items: []
    }
  },

  // WHAT IS CURRENTLY SELECTED
    handleChange(e){
        this.setState({data: e.target.firstChild.data});
    },

  componentDidMount: function() {
    // FETCHES DATA FROM APIS
    var th = this;
    this.serverRequest = 
      axios.all([
        axios.get('https://api.gousto.co.uk/products/v2.0/categories'),
        axios.get('https://api.gousto.co.uk/products/v2.0/products?includes[]=categories&amp;includes[]=attributes&amp;sort=position&amp;image_sizes[]=365&amp;image_sizes[]=400&amp;period_id=120')
      ])
      .then(axios.spread(function (categoriesResponse, itemsResponse) {
        //... but this callback will be executed only when both requests are complete.
        console.log('Categories', categoriesResponse.data.data);
        console.log('Item', itemsResponse.data.data);
        th.setState({
            category: categoriesResponse.data.data,
            items : itemsResponse.data.data,
          });
      }));


  },

  componentWillUnmount: function() {
    this.serverRequest.abort();
  },

  render: function() {
    return (

        &lt;div className="navigation"&gt;
            &lt;h1&gt;Store Cupboard&lt;/h1&gt;
            &lt;NavigationCategoryList data={this.state.category} handleChange={this.handleChange}/&gt;
            &lt;NavigationSubCategoryList data={this.state.category} subData={this.state.items} selected_category={this.state.data} /&gt;
        &lt;/div&gt;
    )
  }
});

var NavigationCategoryList = React.createClass({
    render: function () {
            var handleChange = this.props.handleChange;

        // LOOPS THE CATEGORIES AND OUTPUTS IT
        var links = this.props.data.map(function(category) {
            return (
                &lt;NavigationCategory title={category.title} link={category.id} handleChange={handleChange}/&gt;
            );
        });
        return (
            &lt;div&gt;
                &lt;div className="navigationCategory"&gt;
                    {links}
                &lt;/div&gt;
            &lt;/div&gt;
        );
    }   
});

var NavigationSubCategoryList = React.createClass({
    render: function () {
            var selected = this.props.selected_category;
        var sub = this.props.subData.map(function(subcategory) {
            if(subcategory.categories.title === selected)
            return (
                &lt;NavigationSubCategoryLinks name={subcategory.title} link={subcategory.link}   /&gt;
            );
        });                     
        return (
            &lt;div className="subCategoryContainer"&gt;
                {sub}
            &lt;/div&gt;
        );
    }
});

var NavigationSubCategoryLinks = React.createClass({
    render: function () {
        return (
            &lt;div className="navigationSubCategory" id={this.props.name}&gt;
            {this.props.name}
            &lt;/div&gt;
        );
    }
});   



var NavigationCategory = React.createClass({
    render: function () {
            var handleChange = this.props.handleChange;
        return (
            &lt;div className="navigationLink"&gt;
                &lt;a href={this.props.link} onClick={handleChange}&gt;{this.props.title}&lt;/a&gt;
            &lt;/div&gt;
        );
    }
});



ReactDOM.render(&lt;NavContainer /&gt;, document.getElementById("app"));
</code></pre>

<p>Here is a screenshot of what I have on my webpage so far. Everything just dumps on the screen. The links in blue are the categories.</p>

<p><a href="http://i.stack.imgur.com/ZuCXY.png">Screenshot of current web page</a></p>