React Native Redux: Error Cannot Find MapStateToProps Variable

I am trying to implement Redux in the React-Native registration application I'm working on to create a multi-page form.

I keep getting this error:

enter image description here

Please view the corresponding code here from the root container of the application:

import React, { Component } from 'react';
import ReactNative from 'react-native';
import { AppRegistry,Text,View,} from 'react-native';
import { Button } from 'react-native-elements'
import { StackNavigator } from 'react-navigation'
import store from '../store/store';
import { Provider,connect } from  'react-redux';
import Register1 from './emailandpass'
import Register2   from './namefields'
//import login      from './login'
//import confirmation from './confirmation'
//import success      from './success'

class Loginscreen extends React.Component{
	static navigationOptions= {
		title: 'Welcome to LearnD',
							 }
  render() {
  	const { navigate  } = this.props.navigation;
    return(
      <Provider store={store}> 
      <View>
      <Text>Have you got an account ?</Text>
      <Button
        onPress={()=> navigate('Register1')}
        title="Register here !"
        />
      </View>
      </Provider> 

    );
  }
};

const App = StackNavigator({
 	Home: { screen: Loginscreen},
 	Register1: {screen: Register1  },
 	Register2: {screen: Register2}
});

export default connect(mapStateToProps)(Landingscreen);
Run codeHide result

Any help would be appreciated

+4
source share
3 answers

You have not created a function mapStateToProps, but you are trying to pass it to a function connect.
You should read DOCS for clarity.

For instance:

function mapStateToProps(state) {
  return {
    navigation: state.navigation 
  }
}

This will pass navigationout redux storeas a support for your component so that you can access it throughprops.navigation

+2

.

mapStateToProps connect, .

export default connect(mapStateToProps)(Landingscreen);
//                     ^ this isn't defined anywhere

, :

function mapStateToProps(state) {
  // ...
}
export default connect(mapStateToProps)(Landingscreen);
0

Before using it, you must define a function called mapStateToProps :

const mapStateToProps = ( state ) => {
  const someProp = state.get('someProp');
  return {
    someProp
  }
}
Run codeHide result
0
source

Source: https://habr.com/ru/post/1685833/


All Articles