React原生应用点击登录时出现白屏



我正在尝试在react-native应用程序上构建登录功能,我在同一屏幕上显示api响应,无论是错误还是成功的文本标签,这个功能在android模拟器上完美地工作。当我在手机上安装发布版apk时,当我点击登录时,屏幕变成了白屏。

const [loginUser, {isLoading, error, data, isSuccess, isError}] = useLoginUserMutation();
const OnSignInPressed = async () => {
console.log("onsigninpressed")
const formData = {email, password}
res = await loginUser(formData);
console.log("res", res.data.message)
console.log("resss", res)
if (res.data.message === 'User logged in successfully') {
dispatch(login())
}
}
return (
<View style={styles.root}>
<Text>Api Responses</Text>
{isSuccess && <Text>success message: {data.message}</Text>}
{error && <Text>error message: {error.data.message}</Text>}
{error && <Text>error status: {error.status}</Text>}
<Image source={Logo} style={styles.logo} resizeMode='contain'/>
<Custominput placeholder="Email" value={email} setValue={setEmail}
autoCapitalize='none'/>
<Custominput placeholder="Password" value={password} setValue={setPassword}
secureTextEntry={true}/>
{/* <Custombutton text='Sign In' onPress={OnSignInPressed}/> */}
<Button
onPress={() => OnSignInPressed()}
title="Sign in"
color="#841584"
/>
<Custombutton text='Forgot Password' type="TERTIARY" onPress=.
{onForgotPressed}/>
<Custombutton text="Don't have an account ? Create one" type="TERTIARY"
onPress={onSignupPressed}/>
</View>
)

不应该是res=await loginUser(formData);,应该是const res = await loginUser(formData);

javascript变量必须以const,let,var开头

白屏意味着你在JS端得到一个错误。看起来当你在模拟器上工作时,你会发现这个错误并且不停止应用程序,检查你的控制台。

要添加一个全局错误处理程序,您可以使用以下解决方案https://github.com/a7ul/react-native-exception-handler

最新更新