如何根据 React Native 中的条件渲染元素?
我就是这样尝试的:
render() {
return (
<Text>amount is: {this.state.amount}</Text> // it correctly prints amount value
</Button>
{this.state.amount} >= 85 ? <button>FIRST</button> : <button>SECOND</button>
<Text>some text</Text>
);
}
但是出现了这个错误信息:
Expected a component class, got [object Object]
最佳答案
你放错了你的}
:
render() {
return (
<Text>amount is: {this.state.amount}</Text>
{this.state.amount >= 85 ? <button>FIRST</button> : <button>SECOND</button>}
<Text>some text</Text>
);
}
关于javascript - 在 React Native 中根据条件渲染元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41826647/