I have multiple object values called items in the TodoItem component in FlatList.
also, I have a single object value called itemtow
What I'm trying to do is to put the item object value that matches the item object's id value and the itemtow's CommentId value into the result constant.
this is my data and code
item data
item: {id: 163, content: "부모1", createdAt: "2021-03-19T16:23:20.000Z", updatedAt: "2021-03-19T16:23:20.000Z", UserId: 1, …}
item: {id: 164, content: "부모2", createdAt: "2021-03-19T16:23:23.000Z", updatedAt: "2021-03-19T16:23:23.000Z", UserId: 1, …}
item: {id: 165, content: "부모3", createdAt: "2021-03-19T16:23:38.000Z", updatedAt: "2021-03-19T16:23:38.000Z", UserId: 2, …}
item: {id: 166, content: "부모4", createdAt: "2021-03-19T16:23:41.000Z", updatedAt: "2021-03-19T16:23:41.000Z", UserId: 2, …}
itemtow data
itemtow: {id: 268, CommentId: 166, content: "부모4", active: "1", createdAt: "2021-03-19T16:23:41.000Z", updatedAt: "2021-03-20T05:56:24.000Z", …}
expected result data it would be
expected result = {id: 166, content: "부모4", createdAt: "2021-03-19T16:23:41.000Z", updatedAt: "2021-03-19T16:23:41.000Z", UserId: 2, …}
this is my code
(todoList.js)
const TodoList = ({item}) => {
return (
<>
<FlatList
data={singlePost?.Comments}
keyExtractor={(item) => String(item.id)}
ListEmptyComponent={<EmptyItem />}
renderItem={({item}) => (
<TodoItem
item={item}
itemtow={itemtow}
/>
)}
/>
</>
);
};
export default TodoList;
(TodoItem.js)
const TodoItem = ({item ,itemtow}) => {
const result = item.filter((v) => v.id === itemtow.CommentId);
console.log("result:",result);
return (
)
how can i fix my code? i've tried use filter but it doesn't work .