I am currently learning Easy Peasy state for React, and my first error I came across is that todos.map()
is not a function.
Here is the codesandbox link:
Thanks!
I am currently learning Easy Peasy state for React, and my first error I came across is that todos.map()
is not a function.
Here is the codesandbox link:
Thanks!
using useStoreState instead seems to work, like this…
function Todos() {
const todos = useStoreState(state => state.todos.items)
return (
<div>
{todos.map((todo, idx) => (
<h2 key={idx}>{todo}</h2>
))}
</div>
);
}
remember to add useStoreState to your imports too
You can look at the API docs for more info, useStoreState and useStore. They advise not to use useStore
unless you have to. As far as I can tell it would look like this with useStore
(well it seems to work anyway).
todos.getState().todos.items.map(...code)
Thank You Very Much! It worked!