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

React native 如何从父组件重新渲染/刷新子组件,react-native,react-native-ios,react-native-flatlist,React Native,React Native Ios,React Native Flatlist,如何从父组件重新渲染/刷新子组件 家长: 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 onCategorySeeMorePres

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

家长:

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} />;
}
}
导出默认类Home.Component{
建造师(道具){
超级(道具)
render(){
//我有一个选项卡栏,当我点击一个选项卡时,下面的一行被执行
this.childComponent=;
}
}
孩子

导出默认类ChildComponent扩展组件{
render(){
}
现在,在一个特定条件下,我想刷新子组件。
有人能告诉我如何从父组件刷新/重新渲染子组件。

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

  • 使用此.setState()函数更改组件状态
  • 更改从父级提供的组件
  • 这是常用的建议方法

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

    可以使用forceUpdate()方法


    我希望这对您有所帮助

    Ibrahim:我不想重新渲染父对象,我想使用父对象的某些属性重新渲染子对象尝试将一些值作为道具发送给子对象,并使用
    componentWillReceiveProps
    方法根据道具设置状态。
    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}
            />
    }