Created
August 3, 2021 10:27
-
-
Save Pitt-Pauly/864ccc8255811397182f174d9f54e373 to your computer and use it in GitHub Desktop.
get Redux state in devtools console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ref: https://stackoverflow.com/questions/49541235/how-to-get-content-of-redux-store-in-console-without-devtools | |
function getStore() { | |
const appStates = [] | |
const reactRoot = document.getElementById('root') | |
let base | |
try { | |
base = reactRoot._reactRootContainer._internalRoot.current | |
} catch (e) { | |
console.log('Could not get internal root information from reactRoot element') | |
} | |
while (base) { | |
try { | |
state = base.pendingProps.store.getState() | |
// This also sometimes works... | |
// state = base.stateNode.store.getState() | |
appStates.push(state) | |
} catch (e) { | |
// no state | |
} | |
base = base.child | |
} | |
return appStates | |
} | |
const store = getStore() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment