class GoatButton extends Component { state = { goat: undefined }; fetchGoat = () => { fetch('url/to/goat') .then(goat => this.setState({ goat })); } render() { const { goat } = this.state; return ( <div> {goat ? <img src={goat} /> : null} <button onClick={this.fetchGoat}> Fetch Goat </button> </div> ); } }