use separate component for reacting to specific observable
This commit is contained in:
+15
-9
@@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
import logo from './logo.svg';
|
import logo from './logo.svg';
|
||||||
import './App.css';
|
import './App.css';
|
||||||
import { observer } from 'mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
import { TodoList } from './state';
|
import { TodoList, Todo } from './state';
|
||||||
|
|
||||||
const App = observer(({ todos }: { todos: TodoList }) => {
|
const App = observer(({ todos }: { todos: TodoList }) => {
|
||||||
return (
|
return (
|
||||||
@@ -21,18 +21,24 @@ const App = observer(({ todos }: { todos: TodoList }) => {
|
|||||||
Learn React
|
Learn React
|
||||||
</a>
|
</a>
|
||||||
{todos.todos.map((todo, index) => (
|
{todos.todos.map((todo, index) => (
|
||||||
<div key={index}>
|
<TodoListItem key={index} todo={todo} />
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
checked={todo.done}
|
|
||||||
onChange={() => (todo.done = !todo.done)}
|
|
||||||
/>
|
|
||||||
{todo.name}
|
|
||||||
</div>
|
|
||||||
))}
|
))}
|
||||||
</header>
|
</header>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const TodoListItem = observer(({ todo }: { todo: Todo }) => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={todo.done}
|
||||||
|
onChange={() => (todo.done = !todo.done)}
|
||||||
|
/>
|
||||||
|
{todo.name}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
export default App;
|
export default App;
|
||||||
|
|||||||
Reference in New Issue
Block a user