Wrong types with mobx values()
result in Getting started tutorial
#1981
-
Hi! I'm trying to complete the Getting started tutorial, but got typing error from mobx At the step Getting to the UI we are using // in react component
{values(props.store.todos).map(todo => (
<div>
<input type="checkbox" checked={todo.done} onChange={e => todo.toggle()} />
<input type="text" value={todo.name} onChange={e => todo.setName(e.target.value)} />
</div>
))} Store: // somewhere in store
const Todo = types.model({
name: '',
done: false,
})
const Store = types.model({
todos: types.map(Todo),
}); This code works in the sandbox, but I got the typing error about I've searched and found an old issue, but there is no typings discussion. What am I doing wrong? Playground with code from tutorial |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @alexamy! You can use the export default function App() {
return (
<div className='App'>
{Array.from(store.todos.values()).map((todo, i) => (
<p key={i}>{todo.name}</p>
))}
</div>
);
} Nice find though, we should consider updating the documentation to retain the type information, even though the example is in plain JavaScript. |
Beta Was this translation helpful? Give feedback.
Hi @alexamy!
You can use the
values
method on your map to get an iterator object and then create an array from that to retain the type information:Nice find though, we should consider updating the documentation to retain the type information, even though the example is in plain JavaScript.