1.4 KiB
1.4 KiB
id, title, challengeType, isRequired, forumTopicId, localeTitle
id | title | challengeType | isRequired | forumTopicId | localeTitle |
---|---|---|---|---|---|
5a24c314108439a4d403614c | Get State from the Redux Store | 6 | false | 301443 | 从 Redux Store 获取状态 |
Description
getState()
方法检索 Redux store 对象中保存的当前的state
。
Instructions
store
中使用store.getState()
检索state
,并将其分配给新变量currentState
。
Tests
tests:
- text: redux store 的 state 应该有一个初始值 5。
testString: assert(store.getState()===5);
- text: 应该存在一个变量<code>currentState</code>,并为其分配 Redux store 的当前状态。
testString: getUserInput => assert(currentState === 5 && getUserInput('index').includes('store.getState()'));
Challenge Seed
const store = Redux.createStore(
(state = 5) => state
);
// 更改此行下方的代码
Solution
const store = Redux.createStore(
(state = 5) => state
);
// 更改此行下方的代码
const currentState = store.getState();