Files

1.1 KiB
Raw Permalink Blame History

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
5a24c314108439a4d403614e 定義一個 Action Creator 6 301441 define-an-action-creator

--description--

創建 action 後要將 action 發送到 Redux store以便它可以更新其狀態。 在 Redux 中,可以定義動作創建器來完成此任務, action creator 只是一個返回動作的 JavaScript 函數。 換句話說action creator 創建表示動作事件的對象。

--instructions--

定義名爲 actionCreator() 的函數,該函數在調用時返回 action 對象。

--hints--

函數 actionCreator 應該存在。

assert(typeof actionCreator === 'function');

運行 actionCreator 函數應返回 action 對象。

assert(typeof action === 'object');

返回的 action 對象應該有一個值爲 LOGINtype 屬性。

assert(action.type === 'LOGIN');

--seed--

--seed-contents--

const action = {
  type: 'LOGIN'
}
// Define an action creator here:

--solutions--

const action = {
  type: 'LOGIN'
}
const actionCreator = () => {
  return action;
};