Todos.map is not a function

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!

1 Like

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 :slightly_smiling_face:

1 Like

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)

1 Like

Thank You Very Much! It worked!

1 Like