【发布时间】:2017-12-14 18:20:08
【问题描述】:
我正在实现一个小应用程序,我需要在firebase中插入一些数据,然后在数据插入完成后从堆栈中弹出屏幕。
我现在正在调用该动作,并传递一个回调函数以在插入数据后执行,我的代码如下:
EmployeeCreate.js
onButtonPress() {
const { name, phone, shift, navigator } = this.props;
this.props.employeeCreate({ name, phone, shift: shift || 'Monday' }, () => {
console.log('REDIRECT FUNCTION HERE');
navigator.pop({
animated: true, // does the pop have transition animation or does it happen immediately (optional)
animationType: 'fade', // 'fade' (for both) / 'slide-horizontal' (for android) does the pop have different transition animation (optional)
});
});
}
EmployeeActions.js
export const employeeCreate = ({ name, phone, shift }, callbackFunction) => {
const { currentUser } = firebase.auth();
return () => {
firebase.database().ref(`/users/${currentUser.uid}/employees`)
.push({ name, phone, shift })
.then(callbackFunction);
//type: EMPLOYEE_CREATE
};
};
该操作现在没有通过减速器,并且该应用程序似乎运行良好。我只是想知道我是否做得正确,或者是否有更好的方法可以达到相同的结果?
【问题讨论】:
标签: javascript firebase react-native react-redux react-native-navigation