[英]React native app blank white screen on hitting sign in
我正在嘗試在 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>
)
白屏意味着您在 JS 端遇到錯誤。 看起來當你在你的模擬器上工作時你會發現這個錯誤並且不要停止應用程序,檢查你的控制台。
要添加全局錯誤處理程序,您可以使用此解決方案https://github.com/a7ul/react-native-exception-handler
而不是res=await loginUser(formData);
它應該更像是const res = await loginUser(formData);
javascript 變量必須以 const,let,var 開頭
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.