![](/img/trans.png)
[英]i want to use ternary operator in react-native how can i fix my code?
[英]how can i use Conditional Operator in react-native?? this error occure
本机,我想在组件中使用条件运算符
但是当我尝试在 react-native 中使用条件运算符时,这个错误发生了
这是我的代码
import React from 'react';
import styled from 'styled-components/native';
import {FlatList} from 'react-native';
import {useSelector,useDispatch} from 'react-redux';
const Container = styled.View`
`;
const Hey = styled.Text`
`;
const Food = ({navigation}) => {
const {cookUp} = useSelector((state) => state.post);
console.log("cookUp:",cookUp);
return (
{cookUp ? (
<FlatList
data={cookUp}
keyExtractor={(item) => String(item.id)}
// keyExtractor={(item, index) => {
// return `${index}`;
// }}
renderItem={({item}) => (
<Hey>
{item.name}
</Hey>
)}
/>
) : (<Hey>hi</Hey>)
}
);
};
export default Food;
这个错误发生
我不知道我该如何解决...我该怎么做?
尝试删除返回函数中的大括号。
return (
cookUp ? (
<FlatList
data={cookUp}
keyExtractor={(item) => String(item.id)}
// keyExtractor={(item, index) => {
// return `${index}`;
// }}
renderItem={({item}) => (
<Hey>
{item.name}
</Hey>
)}
/>
) :
(<Hey>hi</Hey>)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.