我正在使用 UI Kitten 开发一个反应原生的移动应用程序。我对本机和 UI 小猫都还很陌生,所以我只使用普通的 Javascript 模板和 Typescript 模板。
我有一个功能组件屏幕,如下所示。这个屏幕工作得很好。今天我开始了 REDUX 的实现。
const RequestScreen = ({ navigation }) => {
// code removed for brevity
}
在这个屏幕中,我使用 useEffect 挂钩从我的 API 获取数据
useEffect(() => {
const unsubscribe = navigation.addListener("focus", () => {
getServices();
});
return () => {
unsubscribe;
};
}, [navigation]);
const getServices = async () => {
setLoading(true);
// helper function to call API
await getAllServices().then((response) => {
if (response !== undefined) {
const services = response.service;
setServices(services);
setLoading(false);
}
});
// update redux state
props.getAllServices(services);
};
// code removed for brevity
const mapStateToProps = (state) => state;
const mapDispatchToProps = (dispatch) => ({
getServices: (services) =>
dispatch({
type: Types.GET_SERVICES,
payload: { services },
}),
});
const connectComponent = connect(mapStateToProps, mapDispatchToProps);
export default connectComponent(RequestScreen);
在这行代码上:
props.getAllServices(services);
我不断收到此错误:
[未处理的承诺拒绝:TypeError:未定义不是对象(评估'props.getAllServices')]在node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch at node_modules\regenerator-runtime\runtime.js:293: 29 在调用中
任何时候我在这里尝试在代码中使用“道具”。我遇到错误。如何获得此屏幕上的道具?
我尝试更改屏幕,如下所示,但这也不起作用!
const RequestScreen = ({ navigation, props }) => {
// code removed
}