【问题标题】:How to rerender/refresh a child component from Parent component如何从父组件重新渲染/刷新子组件
【发布时间】:2019-09-13 12:12:04
【问题描述】:

如何从父组件重新渲染/刷新子组件。

家长:

export default class Home extends React.Component {
constructor(props) {
super(props)

render() {
//I have a tab bar, when i tap on a tab the below line gets executed
this.childComponent = <ChildComponent onCategorySeeMorePress={this.categorySeeMoreClicked} />;
}
}

孩子

export default class ChildComponent extends Component {
render() {
 <FlatList
          style={styles.flatlist}
          data={this.state.cardsMainModel.cards}
          renderItem={this._renderItem.bind(this)}
          horizontal={false}
          keyExtractor={this._keyExtractorInfoSection}
        />
}

现在在特定条件下从父级,我想刷新子组件。 有人可以告诉我如何从父组件刷新/重新渲染子组件。

【问题讨论】:

    标签: react-native react-native-ios react-native-flatlist


    【解决方案1】:

    您可以使用两个 vay 重新渲染组件:

    1. 使用 this.setState() 函数改变组件状态,
    2. 更改从父级提供的组件

    这是常用的和建议的方法。

    但如果这些不是你的解决方案:

    你可以使用 forceUpdate() 方法

    希望对你有帮助

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-13
    • 2018-08-12
    • 2019-06-01
    • 1970-01-01
    • 2019-02-26
    • 1970-01-01
    • 2021-12-01
    • 2019-01-31
    相关资源
    最近更新 更多