Pushpendra Yadav
Pushpendra Yadav

Reputation: 219

How to conditionally pass value in props based on state

     {lib.dataFirst.map((el, i) => {
     if (sizeData.sizing === 'IL') {
     return (
    <SizeValues{
    //This block is giving error
    languageData ? 
    product={el.product}:
    product={el.product_fr}
     }

      size={el.size}
      handleChange={e => changeHandler(e, el.id)}
      id={el.id}
                    />
                  );
                }}

The block where I mentioned - '//This block is giving error' is causing the issue. What I am trying to do is based on the state (languageData) I am trying to either send el.product or el.product_fr.

I am trying to know how to conditionally send over props based on the state value. Can Someone help me out here?

Upvotes: 0

Views: 34

Answers (1)

Try this code:

<SizeValues
    product={languageData ? el.product : el.product_fr}
    size={el.size}
    handleChange={e => changeHandler(e, el.id)}
    id={el.id}
/>

Upvotes: 1

Related Questions