我有以下场景。React Native在输入焦点时有条件渲染视图的一部分
function MyComponent() {
return (
<View>
<TextInput ref={ref => (this.input = ref)} style={styles.input} />
{this.input.isFocused() && <Text>Hello World</Text>}
</View>
);
}
这实际工作正常,但我得到警告:
MyComponent的访问是其内部的渲染findNodeHandle。渲染 应该是一个纯函数。
如何有条件地渲染文本块并避免此警告?
为什么不只是'{this.state.isFocused && Hello World }'? –
TheJizel
这是一回事,我总是在返回之前从状态和道具中提取变量。这只是一个约定。 – Freez