Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 反应导航导航到其他屏幕_React Native_Redux_React Redux_Redux Form - Fatal编程技术网

React native 反应导航导航到其他屏幕

React native 反应导航导航到其他屏幕,react-native,redux,react-redux,redux-form,React Native,Redux,React Redux,Redux Form,我尝试登录,当isLoggedIn=true然后导航到Profile,但总是给我错误信息 undefined不是对象(正在计算“\u this.props.navigation”) mycode有什么问题?有人能帮我吗 import React from 'react' import { Image, StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native'

我尝试登录,当
isLoggedIn=true
然后导航到
Profile
,但总是给我错误信息

undefined不是对象(正在计算“\u this.props.navigation”)

mycode有什么问题?有人能帮我吗

import React from 'react'
import {
    Image,
    StyleSheet,
    Text,
    TextInput,
    TouchableOpacity,
    View
} from 'react-native'
import { Field, reduxForm } from 'redux-form'
import { Container, Content, InputGroup, Button , Input, Icon, Item } from 'native-base';
import { login } from '../Action/Action';
import {NavigationActions} from "react-navigation";
import styles from './Style';
import { connect,  } from 'react-redux'

 }
function submit(values) {
    console.log(values);

}
const renderInput = ({ input: { onChange, ...restInput }}) => {
    return <Input onChangeText={onChange} {...restInput} />
}
}
const Form = props => {
    //const {navigate} = this.props.navigation;
    //let _navigateTo;
    if (props.appUser.isLoggedIn) {
        console.log("haloooo");
        const navigateAction = NavigationActions.navigate({
            routeName: 'Profile',
            params: {},
            action: NavigationActions.navigate({ routeName:     'SubProfileRoute'})
        })

        this.props.navigation.dispatch(navigateAction)
    }
    const { handleSubmit } = props
    //console.log(props.appUser);
    return (
        <Container >
            <Content>
                <Content>
                    <View style={styles.container}>
                        <Image source={require('../Assets/Octocat.png')} style={{width: 128, height: 128}} />

                    </View>
                </Content>
                <Content style={{paddingLeft:10,paddingRight:10,paddingBottom:5, paddingTop:30}}>
                    <Item rounded>
                        <Field name="username" component={renderInput} />
                    </Item>
                </Content>
                <Content style={{paddingLeft:10,paddingRight:10}}>
                    <Item rounded>
                        <Field name="password" component={renderInput} />
                    </Item>
                </Content>
                <Content style={{padding:10}}>
                    <Button  onPress={handleSubmit(props.onLogin)} block info>
                        <Text>Login</Text>
                    </Button>
                </Content>
            </Content>

        </Container>

    )
}
const myReduxForm = reduxForm({
    form: 'MyReduxForm', 
})(Form)
function mapStateToProps(state) {
    return {
        appUser: state.appUser,
    }
}

function mapDispatchToProps(dispatch) {
    return {
        onLogin: (data) => { dispatch(login(data)); },
    }
}
export default connect(
    mapStateToProps,
    mapDispatchToProps
)(myReduxForm)
// export default reduxForm({
//     form: 'test'
// })(Form)
// export default reduxForm({
//     form: 'test'
// })(Form)
从“React”导入React
进口{
形象,,
样式表,
文本,
文本输入,
可触摸不透明度,
看法
}从“反应本机”
从“redux form”导入{Field,reduxForm}
从“本机库”导入{容器、内容、输入组、按钮、输入、图标、项目};
从“../Action/Action”导入{login};
从“反应导航”导入{NavigationActions};
从“./Style”导入样式;
从'react redux'导入{connect,}
}
函数提交(值){
console.log(值);
}
常量renderInput=({input:{onChange,…restInput}})=>{
返回
}
}
const Form=props=>{
//const{navigate}=this.props.navigation;
//让我们航行去;
if(props.appUser.isLoggedIn){
控制台日志(“Halooo”);
const navigateAction=NavigationActions.navigate({
routeName:“配置文件”,
参数:{},
操作:NavigationActions.navigate({routeName:'SubfileRoute'})
})
this.props.navigation.dispatch(navigateAction)
}
常量{handleSubmit}=props
//console.log(props.appUser);
返回(
登录
)
}
常量myReduxForm=reduxForm({
表格:“MyReduxForm”,
})(表格)
函数MapStateTops(状态){
返回{
appUser:state.appUser,
}
}
功能图DispatchToprops(调度){
返回{
onLogin:(data)=>{dispatch(login(data));},
}
}
导出默认连接(
MapStateTops,
mapDispatchToProps
)(myReduxForm)
//导出默认reduxForm({
//表格:'测试'
//(表格)
//导出默认reduxForm({
//表格:'测试'
//(表格)
尝试使用。使用组件窗体WithNavigation,如下代码所示

const Form = ({ navigation }) => {
 //..
navigation.navigate('XXX')
}

const FormWithNavigation = withNavigation(Form);

您使用的是
this.props
而不是
props

这个应该有用

const { handleSubmit, navigation: {navigate} } = props

将const Form=props=>{}替换为({navigation})?尝试将
this.props
替换为
props
类似
props.navigation.navigate()