[英]skip passing props in jsx
如何不根据条件通过道具? 我可以做这个
const condition = true
<ThirdPartyComponent custom={() => condition ? <h1>hello<h1> : null}
但是ThirdPartyComponent仍然会为null,我想跳过将自定义属性传递给ThirdPartyComponent。 请注意,我无权访问ThirdPartyComponent。
根据条件渲染组件。 使用三元运算符,如果为true,则传递prop或在其他条件下不传递
你可以这样-
const condition = true;
condition ? (<ThirdPartyComponent custom={value} />) : (<ThirdPartyComponent /> )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.