React native 对象作为React子对象无效(找到:具有键{auth,user}的对象):React Native

React native 对象作为React子对象无效(找到:具有键{auth,user}的对象):React Native,react-native,react-navigation,React Native,React Navigation,我对本地和Firebase都不熟悉。我尝试使用电子邮件和firebase的密码进行基本的登录和注册,看看它是如何工作的。我的应用程序流是,当用户通过身份验证时,它将使用AppStack.js,否则它将使用AuthStack.js,成功登录时,它将导航到主屏幕,注册时也将这样做。我在尝试导航到主屏幕时出错。有人能给我一个解决方案,并解释为什么我在这种情况下会犯这样的错误吗?非常感谢 错误:对象作为React子对象无效(找到:具有键{auth,user}的对象)。如果要呈现子对象集合,请改用数组 这

我对本地和Firebase都不熟悉。我尝试使用电子邮件和firebase的密码进行基本的登录和注册,看看它是如何工作的。我的应用程序流是,当用户通过身份验证时,它将使用AppStack.js,否则它将使用AuthStack.js,成功登录时,它将导航到主屏幕,注册时也将这样做。我在尝试导航到主屏幕时出错。有人能给我一个解决方案,并解释为什么我在这种情况下会犯这样的错误吗?非常感谢

错误:对象作为React子对象无效(找到:具有键{auth,user}的对象)。如果要呈现子对象集合,请改用数组

这是我的App.js

const App = () => {
  const [user, setUser] = useState(null);

  const onStateAuthChanged = user => {
    setUser(user);
  }

  useEffect(() => {
    const subscriber = auth().onAuthStateChanged(onStateAuthChanged);

    return subscriber;
  }, [])

  return (
    <NavigationContainer>
      {user ? <AppStack /> : <AuthStack />}
    </NavigationContainer>
  );
}

export default App;
const-App=()=>{
const[user,setUser]=useState(null);
const onStateAuthChanged=用户=>{
setUser(用户);
}
useffect(()=>{
const subscriber=auth().onAuthStateChanged(onStateAuthChanged);
返回用户;
}, [])
返回(
{用户?:}
);
}
导出默认应用程序;
这是我的AppStack.js

const AppStack = () => {
    return (
        <Stack.Navigator initialRouteName="HomeScreen">
            <Stack.Screen name="HomeScreen" component={HomeScreen} />
            <Stack.Screen name="AboutScreen" component={AboutScreen} />
            <Stack.Screen name="ProfileScreen" component={ProfileScreen} />
        </Stack.Navigator>
    );
}

export default AppStack;
const-AppStack=()=>{
返回(
);
}
导出默认应用堆栈;
这是我的AuthStack.js

const AuthStack = () => {
    return (
        <Stack.Navigator
            initialRouteName="SignInScreen"
        >
            <Stack.Screen name="SignInScreen" component={SignInScreen} />
            <Stack.Screen name="SignUpScreen" component={SignUpScreen} />
        </Stack.Navigator>
    );
}
const AuthStack=()=>{
返回(
);
}
这是我的签名屏幕

const SignInScreen = () => {
    const [email, setEmail] = useState('');
    const [password, setPassword] = useState('');

    const navigation = useNavigation();
    return (
        <View style={styles.container}>
            <View style={styles.header}>
                <View style={styles.textInput}>
                    <TextInput placeholder="Your email" style={styles.input} onChangeText={text => setEmail(text)} />
                    <TextInput placeholder="Your password" style={[styles.input, { marginTop: 15 }]} onChangeText={text => setPassword(text)} />
                </View>
                <TouchableOpacity
                    style={styles.button}
                    onPress={() => {
                        auth().signInWithEmailAndPassword(email, password)
                            .then(() => navigation.navigate('HomeScreen'))
                            .catch(err => console.log(err));
                    }}
                >
                    <Text>LOGIN</Text>
                </TouchableOpacity>
            </View>
            <View style={styles.footer}>
                <TouchableOpacity onPress={() => navigation.navigate("SignUpScreen")}>
                    <Text>Don't have account ? Signup now</Text>
                </TouchableOpacity>
            </View>
        </View>
    );
}
const signnscreen=()=>{
const[email,setEmail]=useState(“”);
const[password,setPassword]=useState(“”);
const navigation=useNavigation();
返回(
setEmail(文本)}/>
设置密码(文本)}/>
{
auth().使用电子邮件和密码登录(电子邮件,密码)
。然后(()=>navigation.navigate('HomeScreen'))
.catch(err=>console.log(err));
}}
>
登录
navigation.navigate(“SignUpScreen”)}>
没有帐户?现在注册
);
}
这是我的屏幕

const SignUpScreen = () => {
    const [email, setEmail] = useState('');
    const [password, setPassword] = useState('');
    const navigation = useNavigation();

    const handleEmailChange = value => {
        setEmail(value);
    }

    const handlePasswordChange = value => {
        setPassword(value);
    }

    const handleSubmitForm = () => {
        auth().createUserWithEmailAndPassword(email, password)
            .then(() => console.log('dang ky thang cong'))
            .catch(err => console.log(err));
    }

    return (
        <View style={styles.container}>
            <View style={styles.header}>
                <View style={styles.textInput}>
                    <TextInput
                        placeholder="Your email"
                        style={styles.input}
                        value={email}
                        onChangeText={(text) => handleEmailChange(text)}
                    />
                    <TextInput
                        placeholder="Your password"
                        style={[styles.input, { marginTop: 15 }]}
                        value={password}
                        onChangeText={(text) => handlePasswordChange(text)}
                    />
                </View>
                <TouchableOpacity style={styles.button} onPress={() => handleSubmitForm()}>
                    <Text>Signup</Text>
                </TouchableOpacity>
            </View>
        </View>
    );
}
const SignUpScreen=()=>{
const[email,setEmail]=useState(“”);
const[password,setPassword]=useState(“”);
const navigation=useNavigation();
const handleEmailChange=值=>{
设置电子邮件(值);
}
const handlePasswordChange=值=>{
设置密码(值);
}
常量handleSubmitForm=()=>{
auth().createUserWithEmailAndPassword(电子邮件,密码)
.然后(()=>console.log('dang ky thang cong'))
.catch(err=>console.log(err));
}
返回(
handleEmailChange(文本)}
/>
handlePasswordChange(文本)}
/>
handleSubmitForm()}>
报名
);
}
这是我的HomeScreen.js

const HomeScreen = () => {
    const [user, setUser] = useState('');

    useEffect(() => {
        const currentUser = auth().currentUser;
        setUser(currentUser);
    }, [])
    return (
        <View style={styles.container}>
            <Text>You logged in as {user}</Text>
        </View>
  
const主屏幕=()=>{
const[user,setUser]=useState(“”);
useffect(()=>{
const currentUser=auth().currentUser;
设置用户(当前用户);
}, [])
返回(
您以{user}身份登录

>我在尝试导航到主屏幕时出错。有人能给我一个解决方案,并解释我在这种情况下出错的原因吗?非常感谢如果您在导航到主屏幕时出错,您应该发布主屏幕的代码