React Filter

    componentDidMount() {
        axios.get(API_BASE_URL+'/search',{params:{
                lan: this.state.lan
            }}).then(response => {
        //    console.log(response.data.data);
            this.setState({products: response.data.data});
        })
            .catch(function (error) {
                console.log(error);
            })
    }


   render() {
        let products= this.state.products.filter(
            (product) => {
                return product.name.toLowerCase().indexOf(this.state.searchstring) !== -1;
            }
        );

        return (
  
{products.map(product =>

    <div className="col-12 col-md-3 col-sm-6 col-lg-2 col-xl-3" key={product.id}>

        <Products name={product.name} id={product.id} image={product.image[0].image_url} price={product.price}  actions={this.handlertest}/>

    </div>
)}
  );


Comments

Popular posts from this blog

React Context API (Hooks and Classes)

Express ejs with mongoose pagination