【发布时间】:2022-01-06 12:13:22
【问题描述】:
我正在尝试渲染一些字符串,但出现错误,有人知道如何解决吗?
代码:
const FormScreen = ({route}) => {
const [userForm, setuserForm] = useState([]);
useEffect(() => {
if (userForm.length > 0) {
console.log('userform',userForm,userForm.length); // not get inside here gives me a eror before it
return
}
else{
setuserForm(route.params.paramKey);
console.log('TEST',userForm,'LENG',userForm.length)} // returns => TEST [] LENG 0
},[userForm])
return (
<SafeAreaView style={{flex: 1}}>
<View style={styles.container}>
<Text style={styles.textStyle}>COLLECTION :</Text>
{userForm.length > 0 ? (
userForm.map((item) => (
<Text key={uuid.v4()}>{item.fields}</Text>
))
) : (
<Text key={uuid.v4()}> Loading ... </Text>
)}
{..}
route.params.paramKey 是一个字符串
route.params.paramKey 字符串 = {"objeto":"CLMobj_test","fields":["abcs","test"],"type":["Date","Text"]}
【问题讨论】:
-
您能否发布完整错误消息的副本/粘贴?这应该更有助于其他人更好地理解问题。
-
@StaceyBurns 事实上这是完整的错误消息
TypeError: undefined is not a function (near '...userForm.map...') This error is located at: {...} -
感谢@Guilherme,您是否尝试过使用 userForm && userForm.length > 0 作为 userForm.map 之前的条件? (而不仅仅是 userForm.length > 0)
-
@StaceyBurns Yeap ,错误仍然存在
-
嗯,看到您最近的编辑,看起来您有一个格式化为字符串的 json 对象。从您的示例中,您是否尝试映射 "abcs" 和 "test" ?给定您提供的字符串,您希望呈现什么?
标签: javascript react-native jsx