I have a FlatList in React Native -
Here's my object that I'm passing on to FlatList.
const [workoutSet, setWorkoutSet] = useState([
{ setNum: 1, reps: 10, weight: 0 },
{ setNum: 2, reps: 10, weight: 0 },
]);
<SetList data={workoutSet} />
Within SetList I'm trying to render the data passed on to here.
export default function SetList(data) {
return (
<>
<FlatList
data={data}
renderItem={(item) => {
<Text style={styles.name}> {item} </Text>;
}}
/>
{console.log(data.data[0].reps)}
</>
);
}
console.log(data.data[0].reps) returns 10, as expected.
However, if I do a console.log inside renderItem, it doesn't print anything. I'd like to access setNum, reps and weight inside renderItem so that I can display a list. What am I doing wrong? I've searched StackOverflow and couldn't find an answer to this. Thanks.
data={data}should bedata={data.data}. Or alternatively you can destructure in the function parameter:function SetList({ data })(If you don't destructure, it's more conventional to call the argumentprops. Consistent naming is important to avoid confusion.)