3

I would like to see the state in my App.js i am importing like this

import configureStore from './src/configureStore'
let store = configureStore()

so i am injecting in my App.js

<Provider store={store} theme={theme}>
  {console.log('11111',store)}
  <NavigationContainer>

in console only i can see this: {dispatch: ƒ, subscribe: ƒ, getState: ƒ, replaceReducer: ƒ, @@observable: ƒ}

how can i see the state?

btw: configureStore is:

import {createStore, applyMiddleware} from 'redux';
import Reducers from './reducers'
import thunk from 'redux-thunk'

export default function configureStore () {
    let store = createStore(Reducers, applyMiddleware(thunk))
    return store
}
signup
  • 135
  • 1
  • 16

2 Answers2

1

You can simply call store.getState() method to get the current state tree of your application. It is equal to the last value returned by the store's reducer.

<Provider store={store} theme={theme}>
  {console.log('11111',store.getState())}
  <NavigationContainer>
Thanhal P A
  • 4,097
  • 3
  • 18
  • 38
1

for this u need Selector hook from "react-redux"

...
import {useSelector} from "react-redux";
...

...
const {yourStateKey} = useSelector((state) => state);
...

this part can be different based how manny store you have

(state) => state

to set state value in store use "useDispatch" hook from "react-redux"

...
import {useDispatch} from "react-redux";
...
const dispatch = useDispatch();
...
dispatch(reduxActions.yourAction(yourValue))
Engazan
  • 470
  • 1
  • 3
  • 16