2017-09-17 4 views
4

나는 다중 페이지 양식을 만들기 위해 노력하고있는 React-Native 등록 앱에 Redux를 구현하려고 시도하고 있습니다.React Native Redux : Error 변수를 찾을 수 없습니다. mapStateToProps

enter image description here

이 응용 프로그램의 루트 컨테이너에서 여기에 관련된 코드를 검토하십시오 : 어떤 도움을 주시면 감사하겠습니다

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{ 
 
\t static navigationOptions= { 
 
\t \t title: 'Welcome to LearnD', 
 
\t \t \t \t \t \t \t } 
 
    render() { 
 
    \t 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({ 
 
    \t Home: { screen: Loginscreen}, 
 
    \t Register1: {screen: Register1 }, 
 
    \t Register2: {screen: Register2} 
 
}); 
 

 
export default connect(mapStateToProps)(Landingscreen);

이 오류가 계속

답변

0

오류는 아주 자명합니다.

mapStateToProps이라는 변수를 connect 함수에 전달하려고했지만 정의한 적이 없습니다.

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

당신은 당신이 connect 기능에 전달하려고 아직 mapStateToProps 기능을 만들지 않은 :

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

당신은 실제로 소품에 상태를 매핑하는 함수를 작성해야합니다.
당신은 DOCS 선명도

에 대한 예를 들어 읽어야 : 당신이 props.navigation

+1

, 당신은'return' 문 및'{}': – nem035

+0

좋은 캐치 한 쌍의 감사를 놓치고있어. 결정된. –

+0

@JakeXuereb이 답변 또는 다른 사람이 귀하의 문제를 해결 한 경우 수락 한 것으로 표시하십시오. –

0

를 통해 액세스 할 수 있도록

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

이 당신의 구성 요소에 소품으로 reduxstore에서 navigation를 전달합니다 당신은해야 함수를 사용하기 전에 mapStateToProps 함수를 정의하십시오.

올바른 함수 정의가 아니다

const mapStateToProps = (state) => { 
 
    const someProp = state.get('someProp'); 
 
    return { 
 
    someProp 
 
    } 
 
}

관련 문제