Home How to change variable value in return of render with reactjs?
Reply: 0

How to change variable value in return of render with reactjs?

user2735 Published in April 27, 2018, 6:42 am
render() {
    let inputText=this.props.searchData
    let Inputreg = inputText.toLowerCase()
    let Product= this.state.Product;
    let flag = 0;
           { this.state.Product.map((obj,index)=> {

                let productNameLow = obj.name.toLowerCase()
                var arr = productNameLow.split(' ');
                let n =(inArray(arr, Inputreg));
                if (n > 0) {
                    return (
                            <div className ="Product" key={index}> 
                                <div className="card">
                                    {<Link to ={{pathname: './ProductDescription' , state: { item: obj } }} className="card-img-top"><img src={obj.thumbBig[0]} alt="" /></Link>}  
                                    <div className="card-body">
                                        <h4 className="card-title">{obj.name}</h4>
                                        <p className="card-text-right"></p>
                                        <input type="button" value="Add to Cart" onClick={e=>this.handleClick(obj.name,obj.price,obj.thumbBig[0],index)}/>
                                        <input type="button" value="Add to Favourite" className="fav-button" id={index} onClick={e=>this.props.getFavourite(index)}/>
                    {flag = 1}// flag value is not being set to 1

                {(() => {
                        if(flag == 1){
                            return (
                                <h2>No such product exist. Try another search</h2>
                    })()} // function is self invoked , although i wanted to invoke this flag condition after my if(n>0) loop is completely iterated. 


I want to return the search products according to the if(n>0)condition and set flag value to 1 , if flag value remains 0 which i have initialized to 0 only , then i want to return only message. But the flag condition should be checked after the completion of if loop.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.338152 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO