import React, { Component } from "react"; import { HashRouter as Router, Route, NavLink } from 'react-router-dom'; import './index.css' function start(txt){ var str1 = "First" if(str1==txt) { return null } else { return } } class Shop extends React.Component { constructor() { super(); this.state ={txt: 'First', list: []}; } onButtonClick(which) { this.load(which); this.setState({ txt: 'Clicked!' }); } load(which){ if(which=='0') { return fetch('/tea/0') .then((response) => response.json()) .then (( responseJson) => { console.log( responseJson) this.setState({ list: responseJson.data }); }) } else if ( which=='1') { return fetch('/tea/1') .then((response) => response.json()) .then (( responseJson) => { console.log( responseJson) this.setState({ list: responseJson.data }); }) } else if ( which=='2') { return fetch('/tea/2') .then((response) => response.json()) .then (( responseJson) => { console.log( responseJson) this.setState({ list: responseJson.data }); }) } else { return fetch('/tea/3') .then((response) => response.json()) .then (( responseJson) => { console.log( responseJson) this.setState({ list: responseJson.data }); }) } }   render() { var test = "First"     return (       
{this.state.txt==test &&

Black Tea

Green Tea

} {this.state.txt==test &&

Herbal Tea

Fruit Tea

} {this.state.txt!=test &&
{this.state.list.map(function(name){ return

{name.name}

{name.description}

})}
}            
    );   } }   export default Shop