简体   繁体   English

跳过jsx中的传递道具

[英]skip passing props in jsx

how to not to pass props base on condition? 如何不根据条件通过道具? I can do this 我可以做这个

const condition = true
<ThirdPartyComponent custom={() => condition ? <h1>hello<h1> : null}

but ThirdPartyComponent will still get null, I want to skip passing custom prop to ThirdPartyComponent. 但是ThirdPartyComponent仍然会为null,我想跳过将自定义属性传递给ThirdPartyComponent。 Note that I don't have access to ThirdPartyComponent. 请注意,我无权访问ThirdPartyComponent。

Render component on basis of condition. 根据条件渲染组件。 Using ternary operator, if true then pass prop or don't pass it on else condition 使用三元运算符,如果为true,则传递prop或在其他条件下不传递

You can do like this - 你可以这样-

const condition = true;
condition ? (<ThirdPartyComponent custom={value} />) : (<ThirdPartyComponent /> )

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

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