Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Redux: Error Can't find variable mapStateToProps

I have been attempting to implement Redux into a React-Native registration app I'm working on to create a multi page form set up.

I keep getting this error:

enter image description here

Please review the pertaining code here under from the app's root container:

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);

Any help would be appreciated

like image 637
Jake Xuereb Avatar asked Oct 17 '22 05:10

Jake Xuereb


1 Answers

You did not create a mapStateToProps function yet you try to pass it to the connect function.
You should read the DOCS for clarity

For example:

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

This will pass the navigation from redux store as a prop to your component so you can access it via props.navigation

like image 142
Sagiv b.g Avatar answered Nov 03 '22 09:11

Sagiv b.g