freeCodeCamp/curriculum/challenges/chinese/03-front-end-libraries/redux/define-an-action-creator.ch...

58 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
id: 5a24c314108439a4d403614e
title: Define an Action Creator
challengeType: 6
isRequired: false
videoUrl: ''
localeTitle: 定义一个Action Creator
---
## Description
<section id="description">创建操作后下一步是将操作发送到Redux存储以便它可以更新其状态。在Redux中您可以定义动作创建器来完成此任务。动作创建者只是一个返回动作的JavaScript函数。换句话说动作创建者创建表示动作事件的对象。 </section>
## Instructions
<section id="instructions">定义一个名为<code>actionCreator()</code>的函数,该函数在调用时返回<code>action</code>对象。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: 函数<code>actionCreator</code>应该存在。
testString: 'assert(typeof actionCreator === "function", "The function <code>actionCreator</code> should exist.");'
- text: 运行<code>actionCreator</code>函数应该返回操作对象。
testString: 'assert(typeof action === "object", "Running the <code>actionCreator</code> function should return the action object.");'
- text: 返回的操作应具有值为<code>LOGIN</code>的键属性类型。
testString: 'assert(action.type === "LOGIN", "The returned action should have a key property type with value <code>LOGIN</code>.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='jsx-seed'>
```jsx
const action = {
type: 'LOGIN'
}
// Define an action creator here:
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>