How to get contents of Redux repository in console without devtools?

With React Devtools installed, I can get the repository:

$r.store.getState()

And how to do it without React Devtools?

+4
source share
3 answers

Option 1

You can attach the repository to windowwhen you are in dev mode, and then you can access if from the console.

if(env === 'dev') { // only an example - you'll need to tailor this to your build system
    window.store = store;
}

Now you can access it directly from the console:

store.getState()

Option 2 (in chrome)

  • After creating the store console.log(store).
  • In the console, right-click the vault and select Store as global variable.
  • You will get a new variable by name temp1(or tempX if you created others).
  • Now you can use temp1.getState().

( ).

+2

, - window :

const myStore = createStore();

if(process.env.NODE_ENV !== 'production') {
  window.store = myStore;
}

, :

store.getState();
+1

- , , -. , . API React.

, -

render() {
  const { store } = this.context;
  console.log(store)
  return(
  ...
  )
}

, connect-redux connect HOC .

, devtools chrome extension Redux? , . !

+1

Source: https://habr.com/ru/post/1695484/


All Articles