【发布时间】:2020-01-14 11:23:32
【问题描述】:
首先,我有一个基本的英语水平。所以希望你能理解。
React Native 中子组件的重新渲染是否有所不同? 举个例子吧:
class App extends React.Component{
constructor(props) {
super(props);
}
render(){
return(
<ChildComponent />
)
}
componentDidMount() {
this.setState({test:'test'})
}
}
这在反应中重新渲染 ChildComponent 一次,但在 React Native ChildComponent 中不重新渲染只有您的初始渲染。为什么?
ps:ChildComponent 在 React 中只有一个 div,在 React Native 中只有一个 Text。
【问题讨论】:
-
你的意思是在 React-native 上看不到 ChildComponent 中的文字?
-
我可以。但是如果我在 ChildComponent 的渲染方法中放置了一个 console.log('test'),在反应时我会看到两次'teste',并且在本机反应一次。欠债不是显示的文本,而是调用 ChildComponent 的方法渲染的次数。
标签: reactjs react-native render rerender