Right now I get React Hook "useSubscribe" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function.
error on my code and try to find a way to make this work.
const TodosList = useMemo(() => {
return lists?.map((list) => {
return (
<div key={list._id}>
{list?.todos?.map((todo) => {
const commentLoading = useSubscribe('card', todo._id);
const todos = useFind(
() =>
Todos.find(
{
todo._id,
},
{sort: {createdAt: 1}},
),
[todo._id, commentLoading()],
);
return (
{
todos.map((todo) => (
<Todo key={todo._id} />
))
}
)
}
)}
</div>
);
});
}, [lists]);
I’m getting the error because I have useSubscribe
and useFind
inside of useMemo
.
Instead of doing this, what could I try?
Thank you in advance!