Redux mapStateToProps call only once

Redux mapStateToProps call only once

Hello,

Hello,

It's been 2 days that I'm stuck with an issue implementing redux in my react native application. I checked many topics but I can't fix my problem.

The problem is that mapStateToProps is called only once but it's not called anymore after executing action. My reducer is called but the state is not updating.

I test my work on android with android studio and emulator.

Here is my code :

App.js:

  <Provider store={createStore(reducers)}>
    <View>
         <MainScreen />
    </View>
  </Provider>

HeaderReducer:

export default (state = INITIAL_STATE, action) => {
  switch (action.type) {
    case SET_HEADER:
      return action.payload;
    default:
      return state;
 }

};

reducers/index.js

import { combineReducers } from 'redux';
import HeaderReducer from './HeaderReducer';

export default combineReducers({ headerText: HeaderReducer, });

actions/index.js

export const SET_HEADER = 'set_header';

export const setHeaderText = (title) => { return { type: SET_HEADER, payload: title, }; };

MainScreen.js

import * as actions from '../actions';

... <Text> {this.props.headerText} </Text> <Button onPress={() => { this.props.setHeaderText(screen: ${SELECTED_PAGE.profile}); this.forceUpdate(); }} >

...

const mapStateToProps = (state) => { const { headerText } = state; return { headerText }; };

export default connect(mapStateToProps, actions)(MainScreen);

I know that I don't need to forceUpdate in the onPress callback but it's just to check the state after call the function.

So when the application start the reducers are called and my mapStateToProps is working. But when I click on my button, my reducers are called, the good action is executed in the switch but my mapStateToProps is not called anymore. When I click a second time if I console.log the state in my reducer I can see that the state is not updated but stay the same than the INITIAL_STATE.

I don't mutate the state in my reducers, I connected everything in my MainScreen.js and I wrapped my app in Provider with store.

I follow a tutorial on Udemy to implement reduc in my app and even I check the code of the tuto on github, I can't find out where the issue is from (https://github.com/StephenGrider/ReactNativeReduxCasts/tree/master/tech_stack)

I think I miss something really obvious but I can't find out what's wrong since 2 days :/

If someone can help, I would appreciate :)

Thanks.

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

React Native App Development Company in New York

Hire top react native app development company in New York to build and develop custom react native mobile apps for Android & iOS with the latest features.

React Native App Development Company in New York

Hire top react native app development company in New York to build and develop custom react native mobile apps for Android & iOS with the latest features.

How to Share Code Between React and React Native

Learn how to share code between React and React Native to avoid duplicating logic. Sharing Code Between React and React-Native: What Not to Share. This question of sharing code between React and React Native, in fact, one of the hot topics among React and React native developers all over the world. React and React-Native allow a learn once write anywhere paradigm. This is great, because one tech team can build both your web app and native mobile experience. The problem is developers hate writing things twice. There have been a couple of efforts to build a unifying technology to write an application once and have it work on both web and native.