反应本地redux连接未定义函数

时间:2019-04-09 11:39:44

标签: react-native redux react-redux react-native-android

我的代码库如下

展览链接

https://snack.expo.io/@mparvez19861/redux-example

app.js

 <Provider store={store}>
                <View style={styles.container}>
                    <Navigator />
                </View>
            </Provider>

Navigator.js

const AuthStack = createStackNavigator({
  // { SignIn: SignInScreen }
  // SignIn: { screen: EmailPwdLogin }
    Login: { screen: LoginScreen },
    Signup: { screen: SignupScreen },
  });
const drNav = createDrawerNavigator(
  {

    Screen2: {
        screen: Screen2
      },
     SignOut: {
      screen: SignOutScreen
    }
  }
)

export default createAppContainer(createSwitchNavigator(
  {
    // screendesign: screendesign,
    SplashScreen: SplashScreen,
    App: drNav,
    AuthStack: AuthStack
  },
  {
    initialRouteName: 'SplashScreen',
  }
));

login.js

  import React, { Component } from 'react';
import { StyleSheet, View, Text, TextInput, Button, Alert } from 'react-native';
import { NavigationActions } from 'react-navigation';
import firebase from 'react-native-firebase';

import { connect } from 'react-redux';
import { getUserData, watchUserLogin } from '../redux/app-redux';



const mapStateToProps = (state) => {
    return {
        userData: state.userData,
    };
}

const mapDispatchToProps = (dispatch) => {
    return {
        getUserData: (user) => { dispatch(getUserData(user)) },
    };
}

class LoginScreen extends Component {

    constructor(props) {
        super(props);
        this.state = {
            userData: null,
            email: "",
            password: "",
        };
    }

    onLoginPress = () => {
        firebase.auth().signInWithEmailAndPassword(this.state.email, this.state.password)
            .then((user) => {
                //this.state.userData = user;
                this.setState({ userData: user })
                this.onGetUserData(user);
               // this.props.navigation.navigate("friendsOnWay");
            }, (error) => { Alert.alert(error.message); });
    }

    onGetUserData = (user) => {
        this.props.getUserData(user);
    }

    onCreateAccountPress = () => {
        // var navActions = NavigationActions.reset({
        //     index: 0,
        //     actions: [NavigationActions.navigate({routeName: "Signup"})]
        // });
        // this.props.navigation.dispatch(navActions);
        // this.props.navigation.navigate("Signup");
    }



    render() {
        return (
            <View style={{ paddingTop: 50, alignItems: "center" }}>

                <Text>Login</Text>

                <TextInput style={{ width: 200, height: 40, borderWidth: 1 }}
                    value={this.state.email}
                    onChangeText={(text) => { this.setState({ email: text }) }}
                    placeholder="Email"
                    keyboardType="email-address"
                    autoCapitalize="none"
                    autoCorrect={false}
                />

                <View style={{ paddingTop: 10 }} />

                <TextInput style={{ width: 200, height: 40, borderWidth: 1 }}
                    value={this.state.password}
                    onChangeText={(text) => { this.setState({ password: text }) }}
                    placeholder="Password"
                    secureTextEntry={true}
                    autoCapitalize="none"
                    autoCorrect={false}
                />

                <Button title="Login" onPress={this.onLoginPress} />
                <Button title="Create account..." onPress={this.onCreateAccountPress} />
            </View>
        );
    }
}

const styles = StyleSheet.create({

});

export default connect(mapStateToProps, mapDispatchToProps)(LoginScreen);

投掷错误

  

TypeError:TypeError:未定义不是函数(评估'(0,   _react.useMemo)')

     

此错误位于:       在ConnectFunction中(由SceneView创建)       在SceneView中(在StackViewLayout.js:784处)       在RCTView中(在View.js:45)       在视图中(位于StackViewLayout.js:783)       在RCTView中(在View.js:45)       在View中(在StackViewLayout.js:782)       在RCTView中(在View.js:45)       在View中(在createAnimatedComponent.js:153处)       在AnimatedComponent中(在StackViewCard.js:69处)       在RCTView中(在View.js:45)       在View中(在createAnimatedComponent.js:153处)       在AnimatedComponent中(在screens.native.js:59处)       在屏幕上(在StackViewCard.js:57上)       在Card中(在createPointerEventsContainer.js:27处)       在容器中(位于StackViewLayout.js:860)       在RCTView中(在View.js:45)       在视图中(在screens.native.js:83处)       在ScreenContainer中(位于StackViewLayout.js:311)       在RCTView中(在View.js:45)       在View中(在createAnimatedComponent.js:153处)       在AnimatedComponent中(在StackViewLayout.js:307处)       在PanGestureHandler中(在StackViewLayout.js:300)       在StackViewLayout中(位于withOrientation.js:30)       在withOrientation中(在StackView.js:79处)       在RCTView中(在View.js:45)       在视图中(在Transitioner.js:214)       在Transitioner中(位于StackView.js:22)       在StackView中(由Navigator创建)       在导航器中(位于createKeyboardAwareNavigator.js:12处)       在KeyboardAwareNavigator中(由SceneView创建)       在SceneView中(由SwitchView创建)       在SwitchView中(由Navigator创建)       在导航器中(位于createAppContainer.js:388)       在NavigationContainer中(在App.js:94)       在RCTView中(在View.js:45)       在View中(在App.js:93)       在提供程序中(在App.js:92处)       在App中(在renderApplication.js:34)       在RCTView中(在View.js:45)       在View中(在AppContainer.js:98)       在RCTView中(在View.js:45)       在View中(在AppContainer.js:115)       在AppContainer中(位于renderApplication.js:33)

     

此错误位于:       在NavigationContainer中(在App.js:94)       在RCTView中(在View.js:45)       在View中(在App.js:93)       在提供程序中(在App.js:92处)       在App中(在renderApplication.js:34)       在RCTView中(在View.js:45)       在View中(在AppContainer.js:98)       在RCTView中(在View.js:45)       在View中(在AppContainer.js:115)       在AppContainer中(在renderApplication.js:33处)ConnectFunction       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-redux \ lib \ components \ connectAdvanced.js:131:41   updateFunctionComponent       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ Renderer \ oss \ ReactNativeRenderer-dev.js:11441:29   updateSimpleMemoComponent       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ Renderer \ oss \ ReactNativeRenderer-dev.js:11352:4   updateMemoComponent       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ Renderer \ oss \ ReactNativeRenderer-dev.js:11224:8   开始工作       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ Renderer \ oss \ ReactNativeRenderer-dev.js:12824:8   performUnitOfWork       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ Renderer \ oss \ ReactNativeRenderer-dev.js:16075:21   工作循环       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ Renderer \ oss \ ReactNativeRenderer-dev.js:16115:41   renderRoot       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ Renderer \ oss \ ReactNativeRenderer-dev.js:16219:15   performWorkOnRoot       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ Renderer \ oss \ ReactNativeRenderer-dev.js:17198:17   performWork       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ Renderer \ oss \ ReactNativeRenderer-dev.js:17099:24   performSyncWork       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ Renderer \ oss \ ReactNativeRenderer-dev.js:17060:14   requestWork       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ Renderer \ oss \ ReactNativeRenderer-dev.js:16925:19   计划工作       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ Renderer \ oss \ ReactNativeRenderer-dev.js:16724:16   scheduleRootUpdate       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ Renderer \ oss \ ReactNativeRenderer-dev.js:17413:15   updateContainerAtExpirationTime       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ Renderer \ oss \ ReactNativeRenderer-dev.js:17447:28   updateContainer       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ Renderer \ oss \ ReactNativeRenderer-dev.js:17537:4   渲染       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ Renderer \ oss \ ReactNativeRenderer-dev.js:18191:20   renderApplication       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ ReactNative \ renderApplication.js:59:34运行       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ ReactNative \ AppRegistry.js:101:10   runApplication       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ ReactNative \ AppRegistry.js:195:26   __callFunction       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ BatchedBridge \ MessageQueue.js:366:47          D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ BatchedBridge \ MessageQueue.js:106:26   __守护       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ BatchedBridge \ MessageQueue.js:314:10   callFunctionReturnFlushedQueue       D:\ Rnd \ React Native \ Project \ WhoAroundMe \ node_modules \ react-native \ Libraries \ BatchedBridge \ MessageQueue.js:105:17

我做错了,请帮忙

3 个答案:

答案 0 :(得分:1)

redux-sagas的7.0.1版本“现在要求最低React版本为16.8.4或更高。”

答案 1 :(得分:1)

我遇到了相同的问题,我使用了react-native版本0.58.6和react-redux版本6.0.1,并且运行良好。

答案 2 :(得分:1)

我遇到了同样的错误。我更新了我的版本,以对上一个版本以及redux和react-redux进行本机反应。然后解决了。希望也对你有用。