gpt4 book ai didi

javascript - react native Redux : Error Can't find variable mapStateToProps

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:11:17 25 4
gpt4 key购买 nike

我一直在尝试将 Redux 实现到 React-Native 注册应用程序中,我正在努力创建一个多页面表单设置。

我一直收到这个错误:

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

任何帮助将不胜感激

最佳答案

您没有创建 mapStateToProps 函数,但您尝试将它传递给 connect 函数。
您应该阅读 DOCS为了清楚起见

例如:

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

这会将来自 redux storenavigation 作为 prop 传递给您的组件,这样您就可以通过 props.navigation 访问它

关于javascript - react native Redux : Error Can't find variable mapStateToProps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46269314/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com