how to make click button in bootstrap and all data are come API

ankur singh :

react
if u can see code below i try to make when i click on true button or false button then according to click dada change and all data come from API

_filterByLaunch = launch => {
    const post = this.state.allPosts.filter(item =>
    item.launch_success === launch
    );
    this.setState({ post });
    }

You can see here and here is API URL https://api.spaceXdata.com/v3/launches?limit=100&launch_success=true

Demo

Gandzal :

when calling _filterByLaunch, pass the boolean type of true and false and not a string 'true' and 'false'. The data type in the response is of type boolean.

launch_success: true //NOT launch_success: 'true'

so use _filterByLaunch(true), NOT _filterByLaunch('true')

    <button class="btn btn-success"  onClick={() => this._filterByLaunch(true)}>true</button>
  <button class="btn btn-success"  onClick={() => this._filterByLaunch(false)}>false</button>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive