I am learning redux follow redux tutorial,when I saw todos
todos-github example something confuse me:
Todo.js
const Todo = ({ onClick, completed, text}) => (
<li
onClick={onClick}
style={{
textDecoration: completed ? 'line-through' : 'none'
}}
>
{text}
</li>
)
TodoList.js
const TodoList = ({ todos, onTodoClick }) => (
<ul>
{
todos.map(todo =>
<Todo
key={todo.id}
{...todo} //how does it work?
onClick={() => onTodoClick(todo.id)}
/>
)}
</ul>
)
todos
is an array ,todo
is an object:
Todo
item's props:
As I know now,the Todo
,TodoList
component function pass on params by using ES6 Destructuring assignment
, but how {...todo}
work ? it must do something to props
, the {}
in this is stand for it's a javascript syntax
,so ...todo
is a Varargs
to Todo
component function? I dont know, any help appreciate.