【问题标题】:RESOLVED React navigation not working react native已解决反应导航不起作用反应本机
【发布时间】:2020-12-29 23:53:51
【问题描述】:

我只是提供一个 console.log(数据)并导航到另一个屏幕。

但我遇到以下错误:

组件异常 undefined 不是对象

我做错了什么?

注意:当我使用时,navigation.goBack() 有效。

代码如下;

错误仍然存​​在

谁能帮帮我??

代码更新

import React, { useRef } from 'react';
import { useNavigation } from '@react-navigation/native';
import { Form } from '@unform/mobile';
import {
  KeyboardAvoidingView,
  Platform,
  ScrollView,
  Image,
} from 'react-native';

import logo from '../../assets/logo.png';

import Input from '../../components/Input';
import Button from '../../components/Button';

import { Container, FormContainer, Title, TitleContainer } from './styles';

export default function SignUp() {
  const formRef = useRef(null);

  const navigation = useNavigation();

  const handleSignUp = data => {
    console.log(data);
    navigation.navigate('SignUpPersonalData', { data });
  };

  return (
    <>
      <KeyboardAvoidingView
        style={{ flex: 1 }}
        behavior={Platform.OS === 'ios' && 'padding'}
        enabled
      >
        <ScrollView keyboardShouldPersistTaps="handled">
          <Container>
            <Image source={logo} />

            <TitleContainer>
              <Title>Crie sua conta</Title>
            </TitleContainer>

            <Form ref={formRef} onSubmit={handleSignUp}>
              <Input
                autoCorrect={false}
                autoCapitalize="none"
                keyboardType="email-address"
                name="email"
                icon="mail"
                placeholder="E-mail"
              />

              <Input
                secureTextEntry
                returnKeyType="send"
                name="password"
                icon="lock"
                placeholder="Senha"
              />

              <Button onPress={() => formRef.current.submitForm()}>
                Continuar
              </Button>
            </Form>
          </Container>
        </ScrollView>
      </KeyboardAvoidingView>
    </>
  );

截图错误:

SX

【问题讨论】:

  • 通过正常的回调你得到数据?如果不放你的表单组件的代码
  • 我通过输入组件的 ref 获取数据,如果我使用 State,我将正常获取数据@anthonywillismuñoz
  • 我查看了官方小吃演示,当你发送数据时它也不起作用。我建议改用 formik
  • 我解决了,谢谢大家
  • 用它可以帮助某人的解决方案给出答案

标签: react-native react-navigation react-native-navigation react-navigation-stack


【解决方案1】:

不要使用useCallback,试试下面的。

const handleSignUp = (data) =>{
    console.log(data);
    navigation.navigate('SignUpPersonalData',{data: data});
}

【讨论】:

  • 你能用所有代码更新你的问题吗?包括进口声明?
  • 代码对我来说看起来不错。到底哪里出错了?可以分享一下错误截图吗?
  • 错误指向 SignUpPersonalData 组件,而不是您列出的 Signup 组件。要确认,请导航到您知道有效的其他组件。或删除 SignUpPersonalData 组件中的所有内容。
猜你喜欢
  • 1970-01-01
  • 2023-01-27
  • 1970-01-01
  • 2021-09-13
  • 2016-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-01
相关资源
最近更新 更多