Files
freeCodeCamp/curriculum/challenges/chinese/03-front-end-libraries/redux/get-state-from-the-redux-store.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

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
5a24c314108439a4d403614c 从 Redux Store 获取状态 6 301443 get-state-from-the-redux-store

--description--

Redux store 对象提供了几种与之交互的方法, 比如,可以使用 getState() 方法检索 Redux store 对象中保存的当前 state

--instructions--

在代码编辑器中可以将上一个挑战中的代码更简洁地重写, 在 store 中使用 store.getState() 检索state,并将其分配给新变量 currentState

--hints--

Redux store 的 state 应该有一个初始值 5。

assert(store.getState() === 5);

应该存在一个变量 currentState,并为其分配 Redux store 的当前状态。

(getUserInput) =>
  assert(
    currentState === 5 && getUserInput('index').includes('store.getState()')
  );

--seed--

--seed-contents--

const store = Redux.createStore(
  (state = 5) => state
);

// Change code below this line

--solutions--

const store = Redux.createStore(
  (state = 5) => state
);

// Change code below this line
const currentState = store.getState();