1
是否有JSX做foollowing?:条件属性反应/ JSX
let jsx;
if (description)
{
jsx = <MyComponent id="1" name={name} description={description} />
}
else
{
jsx = <MyComponent id="1" name={name} />
}
是否有JSX做foollowing?:条件属性反应/ JSX
let jsx;
if (description)
{
jsx = <MyComponent id="1" name={name} description={description} />
}
else
{
jsx = <MyComponent id="1" name={name} />
}
您可以在“MyComponent的”使用defaultProps的更好的方式。所以你不需要发送“描述”给组件。
MyComponent.defaultProps = {
description: "" //Empty or something
}
子组件内部,你可以做
class Child extends React.Component {
render() {
\t \t var toReturn;
\t \t if(this.props.description){
\t \t toReturn =this.props.description;
\t \t }else{
\t \t toReturn = null;
\t \t }
\t \t return (<div>
{toReturn}
</div>);
}
}