道具未使用react-native和redux

问题描述

我尝试将状态与我的组件之一中的props连接起来。 调用mapPropsToState(state)时,我可以看到state正是我想要的。但是,当我尝试记录道具时,出现错误消息:

Uncaught ReferenceError: props is not defined
    at eval (eval at _getCardAndBalance (VM28 Home.bundle:NaN),<anonymous>:1:1)
    at _getCardAndBalance (VM28 Home.bundle:58)
    at Object.onPress (VM28 Home.bundle:235)
    at TouchableText.touchableHandlePress (Text.js:242)
    at TouchableText._performSideEffectsForTransition (Touchable.js:880)
    at TouchableText._receiveSignal (Touchable.js:779)
    at TouchableText.touchableHandleResponderRelease (Touchable.js:491)
    at onResponderRelease (Text.js:194)
    at Object.invokeGuardedCallbackImpl (ReactNativeRenderer-dev.js:286)
    at invokeGuardedCallback (ReactNativeRenderer-dev.js:497)

我不明白我在这里做错了什么以及为什么它不起作用。

这是我的减速器

const initialState = {}

const calReducer = (state = initialState,action:any) => {

    console.log('CAL reducer with type ' + action.type + ' token ' + action.token)

    switch(action.type) {

        case CAL_SEND_OTP_TOKEN:
            return {...state,sendOtpToken: action.token}
        case CAL_VERIFY_OTP_TOKEN:
            return {...state,verifyOtpToken: action.token}
        case CAL_GET_PAY_ACCOUNT:
            return {...state,payAccount: action.cards}
        default:
            return state
    }
}

export default calReducer;

这是我的组件:

const Home = (props: any) => {

  useEffect(() => { 
    console.log("Home --> useEffect() props are: " + props)
  },[])

return (
        <View style={styles.MainContainer}>
              <ScrollView
          scrollEventThrottle={17}
          contentContainerStyle={{ paddingTop: Header_Maximum_Height }}
          onScroll={Animated.event([
            { nativeEvent: { contentOffset: { y: AnimatedHeaderValue } } }
          ],{ useNativeDriver: false })}>
          
            <Text style={styles.TextViewStyle} onPress={ (e) => _getCardAndBalance(e)}>GetCardsAndBalance</Text>
        </ScrollView>
);
};

const mapdispatchToProps = (dispatch:any) => ({
  setCalSendOtpToken: (token: string)  => dispatch(setCalSendOtpToken(token)),})

const mapStatetoProps = (state:any) => { 

  console.log("Home: --> mapStatetoProps(): state is: " + state)
  return {
    sendOtpToken: state.calReducer.sendOtpToken,}
}

export default connect(mapStatetoProps,mapdispatchToProps)(Home);

无论我在哪里以断点停止代码执行,都始终未定义道具。该代码有什么问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)