每次移动到配置文件屏幕时,我都需要调用一个从配置文件屏幕上的数据库读取数据的方法。由于componentDidMount上的调用方法不适合此问题,因此我决定使用react导航事件侦听器didFocus。但是,我无法使用didFocus调用组件方法。
export default class MyProfile extends Component {
//Invoke method on didFocus
static navigationOptions = ({ navigation }) => {
navigation.addListener('didFocus', () => {
this.searchUser();
});
};
//readfromDB
searchUser() {
//some db operations
}
render(){
return();
}
}