Files
freeCodeCamp/curriculum/challenges/chinese/03-front-end-libraries/redux/define-an-action-creator.md
Oliver Eyton-Williams ee1e8abd87 feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

58 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
id: 5a24c314108439a4d403614e
title: 定义一个 Action Creator
challengeType: 6
forumTopicId: 301441
dashedName: define-an-action-creator
---
# --description--
创建 action 后要将 action 发送到 Redux store以便它可以更新其状态。在 Redux 中你可以定义动作创建器来完成此任务action creator 只是一个返回动作的 JavaScript 函数换句话说action creator 创建表示动作事件的对象。
# --instructions--
定义名为`actionCreator()`的函数,该函数在调用时返回`action`对象。
# --hints--
函数`actionCreator`应该存在。
```js
assert(typeof actionCreator === 'function');
```
运行`actionCreator`函数应返回 action 对象。
```js
assert(typeof action === 'object');
```
返回的 action 应具有值为`LOGIN`的键值类型。
```js
assert(action.type === 'LOGIN');
```
# --seed--
## --seed-contents--
```js
const action = {
type: 'LOGIN'
}
// Define an action creator here:
```
# --solutions--
```js
const action = {
type: 'LOGIN'
}
const actionCreator = () => {
return action;
};
```