Files
freeCodeCamp/curriculum/challenges/chinese/03-front-end-libraries/redux/define-an-action-creator.md
camperbot 5075f14248 chore(i18n,learn): processed translations (#41378)
* chore(i8n,learn): processed translations

* Update curriculum/challenges/chinese/01-responsive-web-design/applied-visual-design/use-the-u-tag-to-underline-text.md

Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>

Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com>
Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>
2021-03-05 07:43:24 -08:00

1.1 KiB
Raw 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;
};