简体   繁体   English

如何根据状态有条件地传递道具中的值

[英]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.我提到的块 - '//This block is given error' 导致了问题。 What I am trying to do is based on the state (languageData) I am trying to either send el.product or el.product_fr.我想要做的是基于状态 (languageData) 我试图发送 el.product 或 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?有人可以帮我吗?

Try this code:试试这个代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM