Skip to content

Instantly share code, notes, and snippets.

@Pitt-Pauly
Created August 3, 2021 10:27
Show Gist options
  • Save Pitt-Pauly/864ccc8255811397182f174d9f54e373 to your computer and use it in GitHub Desktop.
Save Pitt-Pauly/864ccc8255811397182f174d9f54e373 to your computer and use it in GitHub Desktop.
get Redux state in devtools console
// 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