Getting entire redux state as a separate JSON file
Asked Answered
L

3

11

I need to get the whole Redux state as a JSON file without payload or action from Redux DevTools, just the state.

Laurin answered 3/12, 2018 at 8:20 Comment(0)
P
3

If you're using React, and have React DevTools installed, there's another way to get the state from within Chrome:

Open React DevTools Components tab and select the top level "Provider": React DevTools Components Tab

Then go to the Console tab and paste this into the prompt: JSON.stringify($r.store.getState()) $r.store.getState()

$r is the currently selected component in react devtools

Pisa answered 8/10, 2019 at 23:20 Comment(2)
Accepted this answer, as this one is better than previousLaurin
This worked for me JSON.stringify($r.props.store.getState())Ailsun
B
12

State -> Raw -> Copy & Paste

Snapshot

Bursarial answered 6/12, 2018 at 12:52 Comment(2)
This is a valid JS object, but it's not technically valid JSON as the keys need to be strings which need to be surrounded by quotes: json.orgTops
when I paste it into my editor and save as *.json it gets formatted correctly (with quotes, etc) 8)Bursarial
P
3

If you're using React, and have React DevTools installed, there's another way to get the state from within Chrome:

Open React DevTools Components tab and select the top level "Provider": React DevTools Components Tab

Then go to the Console tab and paste this into the prompt: JSON.stringify($r.store.getState()) $r.store.getState()

$r is the currently selected component in react devtools

Pisa answered 8/10, 2019 at 23:20 Comment(2)
Accepted this answer, as this one is better than previousLaurin
This worked for me JSON.stringify($r.props.store.getState())Ailsun
A
0
  1. Open Redux devTool => state => raw => Copy all the state
  2. Open the visual code, create a .json file and paste the state into this new file
  3. Install "Prettier" extension.
  4. Right click and choose "Format document with..."

enter image description here

  1. Select "Prettier - Code formatter" enter image description here

It's done in my case :D

Appellate answered 10/5, 2023 at 8:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.