--- id: 5a24c314108439a4d403614c title: Get State from the Redux Store challengeType: 6 isRequired: false forumTopicId: 301443 localeTitle: 从 Redux Store 获取状态 --- ## Description
Redux store 对象提供了几种允许你与之交互的方法,你可以使用getState()方法检索 Redux store 对象中保存的当前的state
## Instructions
在代码编辑器中可以将上一个挑战中的代码更简洁地重写,在store中使用store.getState()检索state,并将其分配给新变量currentState
## Tests
```yml tests: - text: redux store 的 state 应该有一个初始值 5。 testString: assert(store.getState()===5); - text: 应该存在一个变量currentState,并为其分配 Redux store 的当前状态。 testString: getUserInput => assert(currentState === 5 && getUserInput('index').includes('store.getState()')); ```
## Challenge Seed
```jsx const store = Redux.createStore( (state = 5) => state ); // 更改此行下方的代码 ```
## Solution
```js const store = Redux.createStore( (state = 5) => state ); // 更改此行下方的代码 const currentState = store.getState(); ```