Javascript 跳过jsx中的传递道具
如何根据条件不通过道具?我能做到Javascript 跳过jsx中的传递道具,javascript,reactjs,Javascript,Reactjs,如何根据条件不通过道具?我能做到 const condition = true <ThirdPartyComponent custom={() => condition ? <h1>hello<h1> : null} const条件=真 条件你好:空} 但是ThirdPartyComponent仍然会得到null,我想跳过将自定义道具传递给ThirdPartyComponent。请注意,我无权访问第三方组件。根据条件渲染组件。使用三元运算符,如果为真,则在
const condition = true
<ThirdPartyComponent custom={() => condition ? <h1>hello<h1> : null}
const条件=真
条件你好:空}
但是ThirdPartyComponent仍然会得到null,我想跳过将自定义道具传递给ThirdPartyComponent。请注意,我无权访问第三方组件。根据条件渲染组件。使用三元运算符,如果为真,则在else条件下传递prop或不传递 你可以这样做-
const condition = true;
condition ? (<ThirdPartyComponent custom={value} />) : (<ThirdPartyComponent /> )
const条件=true;
条件() : ( )
根据条件渲染组件。使用三元运算符,如果为真,则在else条件下传递prop或不传递
你可以这样做-
const condition = true;
condition ? (<ThirdPartyComponent custom={value} />) : (<ThirdPartyComponent /> )
const条件=true;
条件() : ( )
尝试使用undefined
而不是null
。根据这里的答案:尝试使用undefined
而不是null
。根据这里的答案: