connect doesn't refresh when state change on react-native with reduxPassing props to react-redux container componentUnderstanding React-Redux and mapStateToProps()Redux with React-Native and mapStateToPropsReact-Redux connected component doesn't get updated after state is changedReact-redux connect passes props too lateTypescript error on rendered component when using react-redux connect functionReact Redux - RN slow performanceReact Native and Redux: Component doesn´t rerender after state changedextracting data to state isn't like documentaion - in mapStateToProps in react native and reduxWhy redux mapStateToProps doesn't update component props even if store is updated?

God-Pharaoh's Statue and Finale Of Promise

Why are goodwill impairments on the statement of cash-flows of GE?

Do people who work at research institutes consider themselves "academics"?

Is there any deeper thematic meaning to the white horse that Arya finds in The Bells (S08E05)?

How to redirect stdout to a file, and stdout+stderr to another one?

Will the volt, ampere, ohm or other electrical units change on May 20th, 2019?

What is the effect of the Feeblemind spell on Ability Score Improvements?

What was Varys trying to do at the beginning of S08E05?

Why did the soldiers of the North disobey Jon?

Wireless headphones interfere with Wi-Fi signal on laptop

How to check if comma list is empty?

Understanding Deutch's Algorithm

Would life always name the light from their sun "white"

How do I know which cipher suites can be disabled?

Why were the bells ignored in S8E5?

Do crew rest seats count towards the maximum allowed number of seats per flight attendant?

Were any toxic metals used in the International Space Station?

c++ conditional uni-directional iterator

Does the wearer know what items are in which patch in the Robe of Useful items?

Meaning of "legitimate" in Carl Jung's quote "Neurosis is always a substitute for legitimate suffering."

​Cuban​ ​Primes

Is there any good reason to write "it is easy to see"?

What color to choose as "danger" if the main color of my app is red

What is this weird d12 for?



connect doesn't refresh when state change on react-native with redux


Passing props to react-redux container componentUnderstanding React-Redux and mapStateToProps()Redux with React-Native and mapStateToPropsReact-Redux connected component doesn't get updated after state is changedReact-redux connect passes props too lateTypescript error on rendered component when using react-redux connect functionReact Redux - RN slow performanceReact Native and Redux: Component doesn´t rerender after state changedextracting data to state isn't like documentaion - in mapStateToProps in react native and reduxWhy redux mapStateToProps doesn't update component props even if store is updated?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








3















It's been 5 hours that I'm on the problem but decidedly it does not want to work...



I would like to dispatch the event when onScroll is detected on my home component and receive the status "true" or "false" in my TopNavigation component



For now my reducer works well (with a console.log(nextState) before the render) but I have the impression that the connection does not work with connect(mapStatetoProps)(TopNavigation) because my component does not re-render



Thank you for your answers



//TopNavigation

import React from 'react'
import connect from 'react-redux'


class TopNavigation extends React.Component
constructor(props)
super(props)



componentDidMount()
console.log(this.props.scrollData)



// Render things...

const mapStatetoProps = (state) =>
return
scrollData: state.scrollData



export default connect(mapStatetoProps)(TopNavigation)



// Home

import React from 'react'
import StyleSheet, View, FlatList from 'react-native'
import gStyles from '../../../Styles/global'
import connect from 'react-redux'

// Partials
import ItemBox from '../../Partials/ItemBox'
import TopNavigation from '../../Partials/TopNavigation'

// Data
import recetteData from '../../../api/recetteData'


class Home extends React.Component
constructor(props)
super(props)


render()
return (
<View style=styles.mainContainer>
<FlatList
data=recetteData
keyExtractor=(item) => item.id.toString()
onPress=() => this._toggleSet()
renderItem=( item ) => <ItemBox item=item />
onScroll=(event) => this.props.dispatch( type: "POSITION", value: event.nativeEvent.contentOffset.y )
style=styles.flatListContainer />
<TopNavigation />
</View>
)



export default connect(mapStateToProps)(Home)




//ScrollData Reducer

const initialState =
scrollData:
scrolled: false



function scrollData(state = initialState, action)
let nextState
switch (action.type)
case 'POSITION':
if (action.value > 0)
nextState =
...state,
scrollData:
...state.scrollData,
scrolled: true,
,


else
nextState =
...state,
scrollData:
...state.scrollData,
scrolled: false
,


return nextState.scrollData.scrolled
default:
return state



export default scrollData



//ConfigureStore

import createStore from 'redux';
import buttonPreference from './Reducers/buttonPreference'
import scrollData from './Reducers/scrollData'


export default createStore(/*buttonPreference,*/scrollData)


On console (console.log of componentDidMount of TopNavigation):



Object
"scrolled": false,



But no change when i'm scrolling



Here is my package.json




"main": "node_modules/expo/AppEntry.js",
"scripts":
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"eject": "expo eject"
,
"dependencies":
"expo": "^32.0.6",
"react": "^16.8.3",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.1.tar.gz",
"react-native-elevated-view": "0.0.6",
"react-native-gesture-handler": "^1.1.0",
"react-native-paper": "^2.12.0",
"react-native-responsive-dimensions": "^2.0.1",
"react-navigation": "^2.0.1",
"react-navigation-material-bottom-tabs": "^0.4.0",
"react-redux": "^6.0.1",
"redux": "^4.0.1"
,
"devDependencies":
"babel-preset-expo": "^5.0.0",
"react-test-renderer": "^16.6.0-alpha.8af6728",
"schedule": "^0.4.0"
,
"private": true



Update



Putting on TopNavigation:



//TopNavigation

constructor(props)
super(props)
this.state =
scrolledState: false



componentDidUpdate(prevProps) // Instead of componentDidMount
if (this.props.scrollData.scrolled !== prevProps.scrollData.scrolled)
console.log(this.props.scrollData);
this.setState( scrolledState: this.props.scrollData );




But it still doesn't work, no event or state change...



Update 2



The store seems to be work oroperly, the problem more precisely is that it does not update in real time the component.



If I populate the store, I quite and return to the page using navigation, the data is well changed.



The real question is, why the component does not update in real time with the new store data passed by the reducer...



Update 3



Expo in production mode solved problem...










share|improve this question






























    3















    It's been 5 hours that I'm on the problem but decidedly it does not want to work...



    I would like to dispatch the event when onScroll is detected on my home component and receive the status "true" or "false" in my TopNavigation component



    For now my reducer works well (with a console.log(nextState) before the render) but I have the impression that the connection does not work with connect(mapStatetoProps)(TopNavigation) because my component does not re-render



    Thank you for your answers



    //TopNavigation

    import React from 'react'
    import connect from 'react-redux'


    class TopNavigation extends React.Component
    constructor(props)
    super(props)



    componentDidMount()
    console.log(this.props.scrollData)



    // Render things...

    const mapStatetoProps = (state) =>
    return
    scrollData: state.scrollData



    export default connect(mapStatetoProps)(TopNavigation)



    // Home

    import React from 'react'
    import StyleSheet, View, FlatList from 'react-native'
    import gStyles from '../../../Styles/global'
    import connect from 'react-redux'

    // Partials
    import ItemBox from '../../Partials/ItemBox'
    import TopNavigation from '../../Partials/TopNavigation'

    // Data
    import recetteData from '../../../api/recetteData'


    class Home extends React.Component
    constructor(props)
    super(props)


    render()
    return (
    <View style=styles.mainContainer>
    <FlatList
    data=recetteData
    keyExtractor=(item) => item.id.toString()
    onPress=() => this._toggleSet()
    renderItem=( item ) => <ItemBox item=item />
    onScroll=(event) => this.props.dispatch( type: "POSITION", value: event.nativeEvent.contentOffset.y )
    style=styles.flatListContainer />
    <TopNavigation />
    </View>
    )



    export default connect(mapStateToProps)(Home)




    //ScrollData Reducer

    const initialState =
    scrollData:
    scrolled: false



    function scrollData(state = initialState, action)
    let nextState
    switch (action.type)
    case 'POSITION':
    if (action.value > 0)
    nextState =
    ...state,
    scrollData:
    ...state.scrollData,
    scrolled: true,
    ,


    else
    nextState =
    ...state,
    scrollData:
    ...state.scrollData,
    scrolled: false
    ,


    return nextState.scrollData.scrolled
    default:
    return state



    export default scrollData



    //ConfigureStore

    import createStore from 'redux';
    import buttonPreference from './Reducers/buttonPreference'
    import scrollData from './Reducers/scrollData'


    export default createStore(/*buttonPreference,*/scrollData)


    On console (console.log of componentDidMount of TopNavigation):



    Object
    "scrolled": false,



    But no change when i'm scrolling



    Here is my package.json




    "main": "node_modules/expo/AppEntry.js",
    "scripts":
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "eject": "expo eject"
    ,
    "dependencies":
    "expo": "^32.0.6",
    "react": "^16.8.3",
    "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.1.tar.gz",
    "react-native-elevated-view": "0.0.6",
    "react-native-gesture-handler": "^1.1.0",
    "react-native-paper": "^2.12.0",
    "react-native-responsive-dimensions": "^2.0.1",
    "react-navigation": "^2.0.1",
    "react-navigation-material-bottom-tabs": "^0.4.0",
    "react-redux": "^6.0.1",
    "redux": "^4.0.1"
    ,
    "devDependencies":
    "babel-preset-expo": "^5.0.0",
    "react-test-renderer": "^16.6.0-alpha.8af6728",
    "schedule": "^0.4.0"
    ,
    "private": true



    Update



    Putting on TopNavigation:



    //TopNavigation

    constructor(props)
    super(props)
    this.state =
    scrolledState: false



    componentDidUpdate(prevProps) // Instead of componentDidMount
    if (this.props.scrollData.scrolled !== prevProps.scrollData.scrolled)
    console.log(this.props.scrollData);
    this.setState( scrolledState: this.props.scrollData );




    But it still doesn't work, no event or state change...



    Update 2



    The store seems to be work oroperly, the problem more precisely is that it does not update in real time the component.



    If I populate the store, I quite and return to the page using navigation, the data is well changed.



    The real question is, why the component does not update in real time with the new store data passed by the reducer...



    Update 3



    Expo in production mode solved problem...










    share|improve this question


























      3












      3








      3








      It's been 5 hours that I'm on the problem but decidedly it does not want to work...



      I would like to dispatch the event when onScroll is detected on my home component and receive the status "true" or "false" in my TopNavigation component



      For now my reducer works well (with a console.log(nextState) before the render) but I have the impression that the connection does not work with connect(mapStatetoProps)(TopNavigation) because my component does not re-render



      Thank you for your answers



      //TopNavigation

      import React from 'react'
      import connect from 'react-redux'


      class TopNavigation extends React.Component
      constructor(props)
      super(props)



      componentDidMount()
      console.log(this.props.scrollData)



      // Render things...

      const mapStatetoProps = (state) =>
      return
      scrollData: state.scrollData



      export default connect(mapStatetoProps)(TopNavigation)



      // Home

      import React from 'react'
      import StyleSheet, View, FlatList from 'react-native'
      import gStyles from '../../../Styles/global'
      import connect from 'react-redux'

      // Partials
      import ItemBox from '../../Partials/ItemBox'
      import TopNavigation from '../../Partials/TopNavigation'

      // Data
      import recetteData from '../../../api/recetteData'


      class Home extends React.Component
      constructor(props)
      super(props)


      render()
      return (
      <View style=styles.mainContainer>
      <FlatList
      data=recetteData
      keyExtractor=(item) => item.id.toString()
      onPress=() => this._toggleSet()
      renderItem=( item ) => <ItemBox item=item />
      onScroll=(event) => this.props.dispatch( type: "POSITION", value: event.nativeEvent.contentOffset.y )
      style=styles.flatListContainer />
      <TopNavigation />
      </View>
      )



      export default connect(mapStateToProps)(Home)




      //ScrollData Reducer

      const initialState =
      scrollData:
      scrolled: false



      function scrollData(state = initialState, action)
      let nextState
      switch (action.type)
      case 'POSITION':
      if (action.value > 0)
      nextState =
      ...state,
      scrollData:
      ...state.scrollData,
      scrolled: true,
      ,


      else
      nextState =
      ...state,
      scrollData:
      ...state.scrollData,
      scrolled: false
      ,


      return nextState.scrollData.scrolled
      default:
      return state



      export default scrollData



      //ConfigureStore

      import createStore from 'redux';
      import buttonPreference from './Reducers/buttonPreference'
      import scrollData from './Reducers/scrollData'


      export default createStore(/*buttonPreference,*/scrollData)


      On console (console.log of componentDidMount of TopNavigation):



      Object
      "scrolled": false,



      But no change when i'm scrolling



      Here is my package.json




      "main": "node_modules/expo/AppEntry.js",
      "scripts":
      "start": "expo start",
      "android": "expo start --android",
      "ios": "expo start --ios",
      "eject": "expo eject"
      ,
      "dependencies":
      "expo": "^32.0.6",
      "react": "^16.8.3",
      "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.1.tar.gz",
      "react-native-elevated-view": "0.0.6",
      "react-native-gesture-handler": "^1.1.0",
      "react-native-paper": "^2.12.0",
      "react-native-responsive-dimensions": "^2.0.1",
      "react-navigation": "^2.0.1",
      "react-navigation-material-bottom-tabs": "^0.4.0",
      "react-redux": "^6.0.1",
      "redux": "^4.0.1"
      ,
      "devDependencies":
      "babel-preset-expo": "^5.0.0",
      "react-test-renderer": "^16.6.0-alpha.8af6728",
      "schedule": "^0.4.0"
      ,
      "private": true



      Update



      Putting on TopNavigation:



      //TopNavigation

      constructor(props)
      super(props)
      this.state =
      scrolledState: false



      componentDidUpdate(prevProps) // Instead of componentDidMount
      if (this.props.scrollData.scrolled !== prevProps.scrollData.scrolled)
      console.log(this.props.scrollData);
      this.setState( scrolledState: this.props.scrollData );




      But it still doesn't work, no event or state change...



      Update 2



      The store seems to be work oroperly, the problem more precisely is that it does not update in real time the component.



      If I populate the store, I quite and return to the page using navigation, the data is well changed.



      The real question is, why the component does not update in real time with the new store data passed by the reducer...



      Update 3



      Expo in production mode solved problem...










      share|improve this question
















      It's been 5 hours that I'm on the problem but decidedly it does not want to work...



      I would like to dispatch the event when onScroll is detected on my home component and receive the status "true" or "false" in my TopNavigation component



      For now my reducer works well (with a console.log(nextState) before the render) but I have the impression that the connection does not work with connect(mapStatetoProps)(TopNavigation) because my component does not re-render



      Thank you for your answers



      //TopNavigation

      import React from 'react'
      import connect from 'react-redux'


      class TopNavigation extends React.Component
      constructor(props)
      super(props)



      componentDidMount()
      console.log(this.props.scrollData)



      // Render things...

      const mapStatetoProps = (state) =>
      return
      scrollData: state.scrollData



      export default connect(mapStatetoProps)(TopNavigation)



      // Home

      import React from 'react'
      import StyleSheet, View, FlatList from 'react-native'
      import gStyles from '../../../Styles/global'
      import connect from 'react-redux'

      // Partials
      import ItemBox from '../../Partials/ItemBox'
      import TopNavigation from '../../Partials/TopNavigation'

      // Data
      import recetteData from '../../../api/recetteData'


      class Home extends React.Component
      constructor(props)
      super(props)


      render()
      return (
      <View style=styles.mainContainer>
      <FlatList
      data=recetteData
      keyExtractor=(item) => item.id.toString()
      onPress=() => this._toggleSet()
      renderItem=( item ) => <ItemBox item=item />
      onScroll=(event) => this.props.dispatch( type: "POSITION", value: event.nativeEvent.contentOffset.y )
      style=styles.flatListContainer />
      <TopNavigation />
      </View>
      )



      export default connect(mapStateToProps)(Home)




      //ScrollData Reducer

      const initialState =
      scrollData:
      scrolled: false



      function scrollData(state = initialState, action)
      let nextState
      switch (action.type)
      case 'POSITION':
      if (action.value > 0)
      nextState =
      ...state,
      scrollData:
      ...state.scrollData,
      scrolled: true,
      ,


      else
      nextState =
      ...state,
      scrollData:
      ...state.scrollData,
      scrolled: false
      ,


      return nextState.scrollData.scrolled
      default:
      return state



      export default scrollData



      //ConfigureStore

      import createStore from 'redux';
      import buttonPreference from './Reducers/buttonPreference'
      import scrollData from './Reducers/scrollData'


      export default createStore(/*buttonPreference,*/scrollData)


      On console (console.log of componentDidMount of TopNavigation):



      Object
      "scrolled": false,



      But no change when i'm scrolling



      Here is my package.json




      "main": "node_modules/expo/AppEntry.js",
      "scripts":
      "start": "expo start",
      "android": "expo start --android",
      "ios": "expo start --ios",
      "eject": "expo eject"
      ,
      "dependencies":
      "expo": "^32.0.6",
      "react": "^16.8.3",
      "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.1.tar.gz",
      "react-native-elevated-view": "0.0.6",
      "react-native-gesture-handler": "^1.1.0",
      "react-native-paper": "^2.12.0",
      "react-native-responsive-dimensions": "^2.0.1",
      "react-navigation": "^2.0.1",
      "react-navigation-material-bottom-tabs": "^0.4.0",
      "react-redux": "^6.0.1",
      "redux": "^4.0.1"
      ,
      "devDependencies":
      "babel-preset-expo": "^5.0.0",
      "react-test-renderer": "^16.6.0-alpha.8af6728",
      "schedule": "^0.4.0"
      ,
      "private": true



      Update



      Putting on TopNavigation:



      //TopNavigation

      constructor(props)
      super(props)
      this.state =
      scrolledState: false



      componentDidUpdate(prevProps) // Instead of componentDidMount
      if (this.props.scrollData.scrolled !== prevProps.scrollData.scrolled)
      console.log(this.props.scrollData);
      this.setState( scrolledState: this.props.scrollData );




      But it still doesn't work, no event or state change...



      Update 2



      The store seems to be work oroperly, the problem more precisely is that it does not update in real time the component.



      If I populate the store, I quite and return to the page using navigation, the data is well changed.



      The real question is, why the component does not update in real time with the new store data passed by the reducer...



      Update 3



      Expo in production mode solved problem...







      react-native redux react-redux state connect






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 27 at 11:57







      Nicolas Taraborrelli

















      asked Mar 23 at 15:14









      Nicolas TaraborrelliNicolas Taraborrelli

      266




      266






















          3 Answers
          3






          active

          oldest

          votes


















          1














          You have done everything right for the most part. The problem is with your TopNavigation file. Two important things to keep in mind here:




          1. componentDidMount() is called only once, when your component is rendered for the first time. So even if your connect works correctly, you will not get more than one call to this function. To check if your props are updated correctly, you can have a console.log() inside componentDidUpdate() as follows:



             componentDidUpdate(prevProps) 
            if (this.props.scrollData.scrolled !== prevProps.scrollData.scrolled)
            console.log(this.props.scrollData);





          2. Also keep in mind that this will not cause a re-render of your component. A component re-renders only when the state of the component changes. You can use this change in your props to trigger a state change, which will call the render function again, to trigger a re-render of your component, as follows:



            state = scrolledState: false;

            ...
            ...

            componentDidUpdate(prevProps)
            if (this.props.scrollData.scrolled !== prevProps.scrollData.scrolled)
            // console.log(this.props.scrollData);
            this.setState(scrolledState: this.props.scrollData);




          Hope this helps!






          share|improve this answer























          • Thanks for your return but unfortunately it still doesn't work, the state remains unchanged and I still have no event in the console

            – Nicolas Taraborrelli
            Mar 24 at 11:03


















          1














          That sounds like a bug with environnement. I launched Expo in production mode and it solved problem.



          On folder .expo



          //setting.json


          "hostType": "lan",
          "lanType": "ip",
          "dev": false, // false for production env
          "minify": false,
          "urlRandomness": "53-g5j"




          I hope it can help but it would be desirable to be able to continue working on dev mode...



          I report a bug on expo github






          share|improve this answer
































            0














            The previous answer was right. But to make the code works try the below approach.



            class Home extends React.Component 
            constructor(props)
            super(props);
            this.state =
            scrolling: false;



            makeScroll = (event) =>
            this.props.dispatch( type: "POSITION", value: event.nativeEvent.contentOffset.y
            );
            setTimeout(() => this.setState(scrolling: true), 150);


            render()
            return (
            <View style=styles.mainContainer>
            <FlatList
            data=recetteData
            keyExtractor=(item) => item.id.toString()
            onPress=() => this._toggleSet()
            renderItem=( item ) => <ItemBox item=item />
            onScroll=(event) => this.makeScroll(event)
            style=styles.flatListContainer />
            <TopNavigation />
            </View>
            )



            export default connect(mapStateToProps)(Home)


            Instead of directly dispatch at onScroll event. Pass it into a function and do change the local state inside that after dispatch.






            share|improve this answer























            • Thank you for your reply, but it still doesn't work. I don't need the state for my Home component and my store is receiving dispatch in both cases.

              – Nicolas Taraborrelli
              Mar 24 at 12:51











            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55315191%2fconnect-doesnt-refresh-when-state-change-on-react-native-with-redux%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            You have done everything right for the most part. The problem is with your TopNavigation file. Two important things to keep in mind here:




            1. componentDidMount() is called only once, when your component is rendered for the first time. So even if your connect works correctly, you will not get more than one call to this function. To check if your props are updated correctly, you can have a console.log() inside componentDidUpdate() as follows:



               componentDidUpdate(prevProps) 
              if (this.props.scrollData.scrolled !== prevProps.scrollData.scrolled)
              console.log(this.props.scrollData);





            2. Also keep in mind that this will not cause a re-render of your component. A component re-renders only when the state of the component changes. You can use this change in your props to trigger a state change, which will call the render function again, to trigger a re-render of your component, as follows:



              state = scrolledState: false;

              ...
              ...

              componentDidUpdate(prevProps)
              if (this.props.scrollData.scrolled !== prevProps.scrollData.scrolled)
              // console.log(this.props.scrollData);
              this.setState(scrolledState: this.props.scrollData);




            Hope this helps!






            share|improve this answer























            • Thanks for your return but unfortunately it still doesn't work, the state remains unchanged and I still have no event in the console

              – Nicolas Taraborrelli
              Mar 24 at 11:03















            1














            You have done everything right for the most part. The problem is with your TopNavigation file. Two important things to keep in mind here:




            1. componentDidMount() is called only once, when your component is rendered for the first time. So even if your connect works correctly, you will not get more than one call to this function. To check if your props are updated correctly, you can have a console.log() inside componentDidUpdate() as follows:



               componentDidUpdate(prevProps) 
              if (this.props.scrollData.scrolled !== prevProps.scrollData.scrolled)
              console.log(this.props.scrollData);





            2. Also keep in mind that this will not cause a re-render of your component. A component re-renders only when the state of the component changes. You can use this change in your props to trigger a state change, which will call the render function again, to trigger a re-render of your component, as follows:



              state = scrolledState: false;

              ...
              ...

              componentDidUpdate(prevProps)
              if (this.props.scrollData.scrolled !== prevProps.scrollData.scrolled)
              // console.log(this.props.scrollData);
              this.setState(scrolledState: this.props.scrollData);




            Hope this helps!






            share|improve this answer























            • Thanks for your return but unfortunately it still doesn't work, the state remains unchanged and I still have no event in the console

              – Nicolas Taraborrelli
              Mar 24 at 11:03













            1












            1








            1







            You have done everything right for the most part. The problem is with your TopNavigation file. Two important things to keep in mind here:




            1. componentDidMount() is called only once, when your component is rendered for the first time. So even if your connect works correctly, you will not get more than one call to this function. To check if your props are updated correctly, you can have a console.log() inside componentDidUpdate() as follows:



               componentDidUpdate(prevProps) 
              if (this.props.scrollData.scrolled !== prevProps.scrollData.scrolled)
              console.log(this.props.scrollData);





            2. Also keep in mind that this will not cause a re-render of your component. A component re-renders only when the state of the component changes. You can use this change in your props to trigger a state change, which will call the render function again, to trigger a re-render of your component, as follows:



              state = scrolledState: false;

              ...
              ...

              componentDidUpdate(prevProps)
              if (this.props.scrollData.scrolled !== prevProps.scrollData.scrolled)
              // console.log(this.props.scrollData);
              this.setState(scrolledState: this.props.scrollData);




            Hope this helps!






            share|improve this answer













            You have done everything right for the most part. The problem is with your TopNavigation file. Two important things to keep in mind here:




            1. componentDidMount() is called only once, when your component is rendered for the first time. So even if your connect works correctly, you will not get more than one call to this function. To check if your props are updated correctly, you can have a console.log() inside componentDidUpdate() as follows:



               componentDidUpdate(prevProps) 
              if (this.props.scrollData.scrolled !== prevProps.scrollData.scrolled)
              console.log(this.props.scrollData);





            2. Also keep in mind that this will not cause a re-render of your component. A component re-renders only when the state of the component changes. You can use this change in your props to trigger a state change, which will call the render function again, to trigger a re-render of your component, as follows:



              state = scrolledState: false;

              ...
              ...

              componentDidUpdate(prevProps)
              if (this.props.scrollData.scrolled !== prevProps.scrollData.scrolled)
              // console.log(this.props.scrollData);
              this.setState(scrolledState: this.props.scrollData);




            Hope this helps!







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 24 at 0:08









            Swanky CoderSwanky Coder

            316212




            316212












            • Thanks for your return but unfortunately it still doesn't work, the state remains unchanged and I still have no event in the console

              – Nicolas Taraborrelli
              Mar 24 at 11:03

















            • Thanks for your return but unfortunately it still doesn't work, the state remains unchanged and I still have no event in the console

              – Nicolas Taraborrelli
              Mar 24 at 11:03
















            Thanks for your return but unfortunately it still doesn't work, the state remains unchanged and I still have no event in the console

            – Nicolas Taraborrelli
            Mar 24 at 11:03





            Thanks for your return but unfortunately it still doesn't work, the state remains unchanged and I still have no event in the console

            – Nicolas Taraborrelli
            Mar 24 at 11:03













            1














            That sounds like a bug with environnement. I launched Expo in production mode and it solved problem.



            On folder .expo



            //setting.json


            "hostType": "lan",
            "lanType": "ip",
            "dev": false, // false for production env
            "minify": false,
            "urlRandomness": "53-g5j"




            I hope it can help but it would be desirable to be able to continue working on dev mode...



            I report a bug on expo github






            share|improve this answer





























              1














              That sounds like a bug with environnement. I launched Expo in production mode and it solved problem.



              On folder .expo



              //setting.json


              "hostType": "lan",
              "lanType": "ip",
              "dev": false, // false for production env
              "minify": false,
              "urlRandomness": "53-g5j"




              I hope it can help but it would be desirable to be able to continue working on dev mode...



              I report a bug on expo github






              share|improve this answer



























                1












                1








                1







                That sounds like a bug with environnement. I launched Expo in production mode and it solved problem.



                On folder .expo



                //setting.json


                "hostType": "lan",
                "lanType": "ip",
                "dev": false, // false for production env
                "minify": false,
                "urlRandomness": "53-g5j"




                I hope it can help but it would be desirable to be able to continue working on dev mode...



                I report a bug on expo github






                share|improve this answer















                That sounds like a bug with environnement. I launched Expo in production mode and it solved problem.



                On folder .expo



                //setting.json


                "hostType": "lan",
                "lanType": "ip",
                "dev": false, // false for production env
                "minify": false,
                "urlRandomness": "53-g5j"




                I hope it can help but it would be desirable to be able to continue working on dev mode...



                I report a bug on expo github







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 27 at 12:44

























                answered Mar 27 at 11:38









                Nicolas TaraborrelliNicolas Taraborrelli

                266




                266





















                    0














                    The previous answer was right. But to make the code works try the below approach.



                    class Home extends React.Component 
                    constructor(props)
                    super(props);
                    this.state =
                    scrolling: false;



                    makeScroll = (event) =>
                    this.props.dispatch( type: "POSITION", value: event.nativeEvent.contentOffset.y
                    );
                    setTimeout(() => this.setState(scrolling: true), 150);


                    render()
                    return (
                    <View style=styles.mainContainer>
                    <FlatList
                    data=recetteData
                    keyExtractor=(item) => item.id.toString()
                    onPress=() => this._toggleSet()
                    renderItem=( item ) => <ItemBox item=item />
                    onScroll=(event) => this.makeScroll(event)
                    style=styles.flatListContainer />
                    <TopNavigation />
                    </View>
                    )



                    export default connect(mapStateToProps)(Home)


                    Instead of directly dispatch at onScroll event. Pass it into a function and do change the local state inside that after dispatch.






                    share|improve this answer























                    • Thank you for your reply, but it still doesn't work. I don't need the state for my Home component and my store is receiving dispatch in both cases.

                      – Nicolas Taraborrelli
                      Mar 24 at 12:51















                    0














                    The previous answer was right. But to make the code works try the below approach.



                    class Home extends React.Component 
                    constructor(props)
                    super(props);
                    this.state =
                    scrolling: false;



                    makeScroll = (event) =>
                    this.props.dispatch( type: "POSITION", value: event.nativeEvent.contentOffset.y
                    );
                    setTimeout(() => this.setState(scrolling: true), 150);


                    render()
                    return (
                    <View style=styles.mainContainer>
                    <FlatList
                    data=recetteData
                    keyExtractor=(item) => item.id.toString()
                    onPress=() => this._toggleSet()
                    renderItem=( item ) => <ItemBox item=item />
                    onScroll=(event) => this.makeScroll(event)
                    style=styles.flatListContainer />
                    <TopNavigation />
                    </View>
                    )



                    export default connect(mapStateToProps)(Home)


                    Instead of directly dispatch at onScroll event. Pass it into a function and do change the local state inside that after dispatch.






                    share|improve this answer























                    • Thank you for your reply, but it still doesn't work. I don't need the state for my Home component and my store is receiving dispatch in both cases.

                      – Nicolas Taraborrelli
                      Mar 24 at 12:51













                    0












                    0








                    0







                    The previous answer was right. But to make the code works try the below approach.



                    class Home extends React.Component 
                    constructor(props)
                    super(props);
                    this.state =
                    scrolling: false;



                    makeScroll = (event) =>
                    this.props.dispatch( type: "POSITION", value: event.nativeEvent.contentOffset.y
                    );
                    setTimeout(() => this.setState(scrolling: true), 150);


                    render()
                    return (
                    <View style=styles.mainContainer>
                    <FlatList
                    data=recetteData
                    keyExtractor=(item) => item.id.toString()
                    onPress=() => this._toggleSet()
                    renderItem=( item ) => <ItemBox item=item />
                    onScroll=(event) => this.makeScroll(event)
                    style=styles.flatListContainer />
                    <TopNavigation />
                    </View>
                    )



                    export default connect(mapStateToProps)(Home)


                    Instead of directly dispatch at onScroll event. Pass it into a function and do change the local state inside that after dispatch.






                    share|improve this answer













                    The previous answer was right. But to make the code works try the below approach.



                    class Home extends React.Component 
                    constructor(props)
                    super(props);
                    this.state =
                    scrolling: false;



                    makeScroll = (event) =>
                    this.props.dispatch( type: "POSITION", value: event.nativeEvent.contentOffset.y
                    );
                    setTimeout(() => this.setState(scrolling: true), 150);


                    render()
                    return (
                    <View style=styles.mainContainer>
                    <FlatList
                    data=recetteData
                    keyExtractor=(item) => item.id.toString()
                    onPress=() => this._toggleSet()
                    renderItem=( item ) => <ItemBox item=item />
                    onScroll=(event) => this.makeScroll(event)
                    style=styles.flatListContainer />
                    <TopNavigation />
                    </View>
                    )



                    export default connect(mapStateToProps)(Home)


                    Instead of directly dispatch at onScroll event. Pass it into a function and do change the local state inside that after dispatch.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 24 at 12:05









                    Prabu samvelPrabu samvel

                    915312




                    915312












                    • Thank you for your reply, but it still doesn't work. I don't need the state for my Home component and my store is receiving dispatch in both cases.

                      – Nicolas Taraborrelli
                      Mar 24 at 12:51

















                    • Thank you for your reply, but it still doesn't work. I don't need the state for my Home component and my store is receiving dispatch in both cases.

                      – Nicolas Taraborrelli
                      Mar 24 at 12:51
















                    Thank you for your reply, but it still doesn't work. I don't need the state for my Home component and my store is receiving dispatch in both cases.

                    – Nicolas Taraborrelli
                    Mar 24 at 12:51





                    Thank you for your reply, but it still doesn't work. I don't need the state for my Home component and my store is receiving dispatch in both cases.

                    – Nicolas Taraborrelli
                    Mar 24 at 12:51

















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55315191%2fconnect-doesnt-refresh-when-state-change-on-react-native-with-redux%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript