mobxjs / mobx-react

React bindings for MobX
https://mobx.js.org/react-integration.html
MIT License
4.85k stars 350 forks source link

How to structure the TodoList and TodoItem with useLocalStore #875

Closed geohuz closed 4 years ago

geohuz commented 4 years ago

I'm stumble upon structuring my code according the following code in the document:

const Todo = () => {
    const todo = useLocalStore(() => ({
        title: "Test",
        done: true,
        toggle() {
            this.done = !this.done
        }
    }))

    return useObserver(() => (
        <h1 onClick={todo.toggle}>
            {todo.title} {todo.done ? "[DONE]" : "[TODO]"}
        </h1>
    ))
}

I can't figure out hwo to write my TodoList component's localStore? Or Should I just put the todos: [] inside the Todo component? I think I need more example code to help me out. Thanks!

danielkcz commented 4 years ago

Please, don't double post, it won't expedite anything, just annoy people.