我試圖映射我的 userForm 狀態以逐個渲染每個狀態,但是 map 函式有時將我回傳為 undefiend,有時回傳為一個無限回圈,我沒有找到解決它的方法,有人可以幫助我嗎?
我的代碼:
const FormScreen = async({route}) => {
const [userForm, setuserForm] = useState([]);
if (userForm.length > 0) {
console.log(userForm,'campos:',userForm.fields);
return;
} else {
setuserForm(await JSON.parse(route.params.paramKey));
}
{...}
return (
<SafeAreaView style={{flex: 1}}>
<View style={styles.container}>
<Text style={styles.textStyle}>
COLLECTION :
</Text>
{userForm.map((item) => (
<Text keys={item.fields}>test</Text>
))}
</View>
</SafeAreaView>
);
};
uj5u.com熱心網友回復:
移動setuserForm(await JSON.parse(route.params.paramKey));到一個useEffect鉤子里。
https://reactjs.org/docs/hooks-effect.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/369215.html
標籤:javascript 反应原生 jsx
