UI Kitten 功能组件 - 道具未定义

时间:2021-04-09 20:59:43

标签: react-native react-native-ui-kitten

我正在使用 UI Kitten 开发 React Native 移动应用程序。我对 React Native 和 UI kitten 还是很陌生,所以我只使用普通的 Javascript 模板 VS 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: undefined is not an object (评估 'props.getAllServices')] 在 node_modules\regenerator-runtime\runtime.js:63:36 在 tryCatch 中 node_modules\regenerator-runtime\runtime.js:293:29 invoke

每当我尝试在此处的代码中使用“道具”时。我遇到了错误。 如何在此屏幕上获取道具?

我尝试更改屏幕,如下所示,但也不起作用!

const RequestScreen = ({ navigation, props }) => {
  // code removed
}

1 个答案:

答案 0 :(得分:0)

更改屏幕组件后,我能够获取 props 对象,如下所示。

const RequestScreen = ({ navigation, ...props }) => {}