DeviceEventEmitter
从C页面跳转到A页面,并不会调用render,而A页面的数据此时需要刷新,怎么办?使用DeviceEventEmitter
import {DeviceEventEmitter} from 'react-native';
componentDidMount() {
this.subscription = DeviceEventEmitter.addListener('UPDATE_USER_DATA', this.refreshData)
};
refreshData(data) {
this.setState({
data: data,
});
};
componentWillUnmount() {
this.subscription.remove();
};
C页面的action文件中
export function addHijackPassword(navigation, holdingPassword) {
navigation.navigate('A')
return (dispatch, getState) => {
....
DeviceEventEmitter.emit('UPDATE_USER_DATA');
}
}