javascript - 没有 if 语句的 React Native Conditional Rendering
问题描述
是否可以在不使用渲染部分中的 if/else 语句的情况下重新渲染特定组件。因此,当特定语句更改时,只有他的特定组件将重新渲染,而其余部分保持不变。
因为如果我使用 componentWillUpdate 或 shouldComponentUpdate 它将再次重新渲染整个应用场景。
我期待着你的回答。
解决方案
你可以尝试类似的东西 -
class MainComponent extends React.Component {
displayMessage() {
if (this.props.isGreeting) {
return <Text> Hello, JSX! </Text>;
} else {
return <Text> Goodbye, JSX! </Text>;
}
}
render() {
return ( <View> { this.displayMessage() } </View> );
}
}
检查这篇文章 - https://medium.com/@szholdiyarov/conditional-rendering-in-react-native-286351816db4
推荐阅读
- java - Tomcat 9 Valve 导致服务器启动失败
- c - 如何在 C 中执行 DLL 中的线程
- javascript - 向对象数组添加数据时如何防止重复键?
- php - 从文件获取内容获取json字符串时获取对象字符串(php)
- c# - 让应用程序以不同于 Windows 服务的用户身份运行
- python-3.x - 如何在 Databricks 中安装 PYODBC
- jenkins - 如何在轻量级执行器上运行管道时将重量级帖子与 Jenkins 声明性管道一起使用
- python - Cython for pypi 包结构
- vb.net - 如何通过两个不同的拆分选项提取字符串?
- java - 为什么在我的代码中使用 Apache POI 后结果会立即发生变化?