actions中的index.js和reducers中的index.js语法求助
来源:4-4 action的处理器:reducer

toseeabetterme
2019-03-12
在actions中的index.js,输出的函数如下:
export const addTodo = (text)=>({
type : ADD_TODO,
id : netxTodoID++,
text,
completed : false
})
上面的函数主题用括号括起来了。
在reducers中的函数为:
export const todoApp = (state,action) =>{
switch (action.type) {
case ADD_TODO:
return {
}
case TOGGLE_TODO:
case SET_FILTER:
case SET_TODO_TEXT:
default:
}
}
这个里面的(state,action)=>后面没有跟一个括号,
请教老师这里面加不加括号有区别吗?
写回答
1回答
-
你好。
export const addTodo = (text)=>({ type : ADD_TODO, id : netxTodoID++, text, completed : false })
等价于
export const addTodo = (text)=>{ return { type : ADD_TODO, id : netxTodoID++, text, completed : false } }
第一种写法是一种简写。
祝学习顺利!
422020-05-25
相似问题