2018-09-30 23:01:58 +01:00
---
id: 5a24c314108439a4d403614c
title: Get State from the Redux Store
challengeType: 6
2019-08-05 09:17:33 -07:00
forumTopicId: 301443
2021-01-13 03:31:00 +01:00
dashedName: get-state-from-the-redux-store
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
The Redux store object provides several methods that allow you to interact with it. For example, you can retrieve the current `state` held in the Redux store object with the `getState()` method.
# --instructions--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
The code from the previous challenge is re-written more concisely in the code editor. Use `store.getState()` to retrieve the `state` from the `store` , and assign this to a new variable `currentState` .
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --hints--
2018-09-30 23:01:58 +01:00
2021-02-25 09:19:24 -08:00
The Redux store should have a value of 5 for the initial state.
2018-09-30 23:01:58 +01:00
2020-07-13 18:58:50 +02:00
```js
2020-11-27 19:02:05 +01:00
assert(store.getState() === 5);
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
A variable `currentState` should exist and should be assigned the current state of the Redux store.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
(getUserInput) =>
assert(
currentState === 5 & & getUserInput('index').includes('store.getState()')
);
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
# --seed--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
## --seed-contents--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
const store = Redux.createStore(
(state = 5) => state
);
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
// Change code below this line
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
```js
const store = Redux.createStore(
(state = 5) => state
);
2020-09-15 09:53:25 -07:00
// Change code below this line
2018-09-30 23:01:58 +01:00
const currentState = store.getState();
```