Answer the question
In order to leave comments, you need to log in
Flatlist not updating?
There is a Parent component
class Parent extends React.Component {
constructor(props){
super(props);
this.state={data:[]}
}
componentDidMount(){
/*Загружаю данные с сервера*/
}
render(){
return(
<Child data={this.state.data} refresh={this.state.refresh}/>
)
}
}
class Child extends React.Component {
constructor(props){
super(props);
this.state={refresh:this.props.refresh}
}
render(){
<FlatList
keyExtractor = {( item, index ) => index.id }
data = { this.props.data}
renderItem={this.renderItem.bind(this)}
extraData={this.props.refresh}{/*поставил даже extraData={this.props},extraData={this.state.refresh} или даже подписался на родительский компонент чтобы обновить не вышло.*/}
/>
)
}
}
Answer the question
In order to leave comments, you need to log in
In theory, you can push this.props.data into extraData and a re-render will be called when it changes. Is the data updated correctly in the child component? You can check in the deprecated componentWillReceiveProps whether new props are coming to it. And in general, how does the update happen in componentDidMount? I hope through this.setState, and not directly?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question