React component doesn't update after updating state with redux actionWhy do we need middleware for async flow in Redux?How to dispatch a Redux action with a timeout?Understanding React-Redux and mapStateToProps()What is mapDispatchToProps?Redux with React-Native and mapStateToPropsreact component connected, redux state changes… but no update to component?React-Redux connected component doesn't get updated after state is changedReact-redux tutorial : Where does children come fromTypescript error on rendered component when using react-redux connect functionRedux - mapDispatchToProps - TypeError: _this.props.setCurrentUserHandle is not a function

How do the Durable and Dwarven Fortitude feats interact?

Are there any rules on how characters go from 0th to 1st level in a class?

Did Michelle Obama have a staff of 23; and Melania have a staff of 4?

Designing a prison for a telekinetic race

Eric Andre had a dream

Meaning and structure of headline "Hair it is: A List of ..."

What are some tips and tricks for finding the cheapest flight when luggage and other fees are not revealed until far into the booking process?

How does the illumination of the sky from the sun compare to that of the moon?

Subgroup generated by a subgroup and a conjugate of it

How to render "have ideas above his station" into German

Why was ramjet fuel used as hydraulic fluid during Saturn V checkout?

How could Tony Stark wield the Infinity Nano Gauntlet - at all?

Is it alright to say good afternoon Sirs and Madams in a panel interview?

Why do aircraft leave cruising altitude long before landing just to circle?

Can I use images from my published papers in my thesis without copyright infringment?

If it isn't [someone's name]!

Programming a recursive formula into Mathematica and find the nth position in the sequence

Do predators tend to have vertical slit pupils versus horizontal for prey animals?

Quick destruction of a helium filled airship?

The Lucky House

Adding things to bunches of things vs multiplication

Build a mob of suspiciously happy lenny faces ( ͡° ͜ʖ ͡°)

Can I submit a paper computer science conference using an alias if using my real name can cause legal trouble in my original country

Do I need to start off my book by describing the character's "normal world"?



React component doesn't update after updating state with redux action


Why do we need middleware for async flow in Redux?How to dispatch a Redux action with a timeout?Understanding React-Redux and mapStateToProps()What is mapDispatchToProps?Redux with React-Native and mapStateToPropsreact component connected, redux state changes… but no update to component?React-Redux connected component doesn't get updated after state is changedReact-redux tutorial : Where does children come fromTypescript error on rendered component when using react-redux connect functionRedux - mapDispatchToProps - TypeError: _this.props.setCurrentUserHandle is not a function






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















/keywordsActions



import UPDATE_KEYWORDS from "./actionTypes";
import queryString from "query-string";

const keywordsArrayFromUrl = () =>
const query = queryString.parse(window.location.search);
if (query.keywords)
const removeDuplicate = new Set(query.keywords.split(" "));
return Array.from(removeDuplicate);


return [];
;

export function updateKeywords()
return async dispatch =>
dispatch(
type: UPDATE_KEYWORDS,
payload: await keywordsArrayFromUrl()
);
;



/keywordReducer



import UPDATE_KEYWORDS from "../actions/actionTypes";

export default function(state = [], action)
switch (action.type)
case UPDATE_KEYWORDS:
return action.payload;
default:
return state;




/SearchBar -- React Component



import React, Component from "react";
import withRouter from "react-router-dom";
//Redux
import connect from "react-redux";
import updateKeywords from "../store/actions/KeywordsAction";

class Searchbar extends Component
constructor(props)
super(props);
this.state =
keywords : this.props.keywords
keywordsString: this.props.keywords.join(" ")
;


componentDidMount()
this.props.updateKeywords();
console.log(this.props)
setTimeout(() => console.log(this.props), 10);


_handleChange = e =>
this.setState( keywordsString: e.target.value );
;

_handleSearch = value =>
this.setState( keywordsString: value );
this.props.history.push(`/search?keywords=$value`);
;

render()
return (
<Search
className="Searchbar"
placeholder="Cauta prin iBac..."
value=this.state.keywordsString
onChange=this._handleChange
onSearch=this._handleSearch
/>
);



const mapStateToProps = state =>
return
keywords: state.keywords
;
;

export default connect(
mapStateToProps,
updateKeywords
)(withRouter(Searchbar));


I want to save the keywords from the Url to the store and then pass it to the Search bar state.



But i dont understand this :



 componentDidMount() 
this.props.updateKeywords();
console.log(this.props); // this.props.keywords is empty
setTimeout(() => console.log(this.props), 10); // After 10 ms this.props.keywords is no empty



After 10 ms the props of Searchbar gets updated but the component doesn't render again.



Sorry for my question, I am really new to React / Redux. Please let me know what I am doing wrong. Thank you all!



Update :



 componentDidMount() 
this.props.updateKeywords();
setTimeout(() =>
this.setState(
keywordsString: this.props.keywords.join(" ")
);
, 0);



This code is also working... but this other is not working



componentDidMount() 
this.props.updateKeywords();
this.setState(
keywordsString: this.props.keywords.join(" ")
);










share|improve this question
































    1















    /keywordsActions



    import UPDATE_KEYWORDS from "./actionTypes";
    import queryString from "query-string";

    const keywordsArrayFromUrl = () =>
    const query = queryString.parse(window.location.search);
    if (query.keywords)
    const removeDuplicate = new Set(query.keywords.split(" "));
    return Array.from(removeDuplicate);


    return [];
    ;

    export function updateKeywords()
    return async dispatch =>
    dispatch(
    type: UPDATE_KEYWORDS,
    payload: await keywordsArrayFromUrl()
    );
    ;



    /keywordReducer



    import UPDATE_KEYWORDS from "../actions/actionTypes";

    export default function(state = [], action)
    switch (action.type)
    case UPDATE_KEYWORDS:
    return action.payload;
    default:
    return state;




    /SearchBar -- React Component



    import React, Component from "react";
    import withRouter from "react-router-dom";
    //Redux
    import connect from "react-redux";
    import updateKeywords from "../store/actions/KeywordsAction";

    class Searchbar extends Component
    constructor(props)
    super(props);
    this.state =
    keywords : this.props.keywords
    keywordsString: this.props.keywords.join(" ")
    ;


    componentDidMount()
    this.props.updateKeywords();
    console.log(this.props)
    setTimeout(() => console.log(this.props), 10);


    _handleChange = e =>
    this.setState( keywordsString: e.target.value );
    ;

    _handleSearch = value =>
    this.setState( keywordsString: value );
    this.props.history.push(`/search?keywords=$value`);
    ;

    render()
    return (
    <Search
    className="Searchbar"
    placeholder="Cauta prin iBac..."
    value=this.state.keywordsString
    onChange=this._handleChange
    onSearch=this._handleSearch
    />
    );



    const mapStateToProps = state =>
    return
    keywords: state.keywords
    ;
    ;

    export default connect(
    mapStateToProps,
    updateKeywords
    )(withRouter(Searchbar));


    I want to save the keywords from the Url to the store and then pass it to the Search bar state.



    But i dont understand this :



     componentDidMount() 
    this.props.updateKeywords();
    console.log(this.props); // this.props.keywords is empty
    setTimeout(() => console.log(this.props), 10); // After 10 ms this.props.keywords is no empty



    After 10 ms the props of Searchbar gets updated but the component doesn't render again.



    Sorry for my question, I am really new to React / Redux. Please let me know what I am doing wrong. Thank you all!



    Update :



     componentDidMount() 
    this.props.updateKeywords();
    setTimeout(() =>
    this.setState(
    keywordsString: this.props.keywords.join(" ")
    );
    , 0);



    This code is also working... but this other is not working



    componentDidMount() 
    this.props.updateKeywords();
    this.setState(
    keywordsString: this.props.keywords.join(" ")
    );










    share|improve this question




























      1












      1








      1


      1






      /keywordsActions



      import UPDATE_KEYWORDS from "./actionTypes";
      import queryString from "query-string";

      const keywordsArrayFromUrl = () =>
      const query = queryString.parse(window.location.search);
      if (query.keywords)
      const removeDuplicate = new Set(query.keywords.split(" "));
      return Array.from(removeDuplicate);


      return [];
      ;

      export function updateKeywords()
      return async dispatch =>
      dispatch(
      type: UPDATE_KEYWORDS,
      payload: await keywordsArrayFromUrl()
      );
      ;



      /keywordReducer



      import UPDATE_KEYWORDS from "../actions/actionTypes";

      export default function(state = [], action)
      switch (action.type)
      case UPDATE_KEYWORDS:
      return action.payload;
      default:
      return state;




      /SearchBar -- React Component



      import React, Component from "react";
      import withRouter from "react-router-dom";
      //Redux
      import connect from "react-redux";
      import updateKeywords from "../store/actions/KeywordsAction";

      class Searchbar extends Component
      constructor(props)
      super(props);
      this.state =
      keywords : this.props.keywords
      keywordsString: this.props.keywords.join(" ")
      ;


      componentDidMount()
      this.props.updateKeywords();
      console.log(this.props)
      setTimeout(() => console.log(this.props), 10);


      _handleChange = e =>
      this.setState( keywordsString: e.target.value );
      ;

      _handleSearch = value =>
      this.setState( keywordsString: value );
      this.props.history.push(`/search?keywords=$value`);
      ;

      render()
      return (
      <Search
      className="Searchbar"
      placeholder="Cauta prin iBac..."
      value=this.state.keywordsString
      onChange=this._handleChange
      onSearch=this._handleSearch
      />
      );



      const mapStateToProps = state =>
      return
      keywords: state.keywords
      ;
      ;

      export default connect(
      mapStateToProps,
      updateKeywords
      )(withRouter(Searchbar));


      I want to save the keywords from the Url to the store and then pass it to the Search bar state.



      But i dont understand this :



       componentDidMount() 
      this.props.updateKeywords();
      console.log(this.props); // this.props.keywords is empty
      setTimeout(() => console.log(this.props), 10); // After 10 ms this.props.keywords is no empty



      After 10 ms the props of Searchbar gets updated but the component doesn't render again.



      Sorry for my question, I am really new to React / Redux. Please let me know what I am doing wrong. Thank you all!



      Update :



       componentDidMount() 
      this.props.updateKeywords();
      setTimeout(() =>
      this.setState(
      keywordsString: this.props.keywords.join(" ")
      );
      , 0);



      This code is also working... but this other is not working



      componentDidMount() 
      this.props.updateKeywords();
      this.setState(
      keywordsString: this.props.keywords.join(" ")
      );










      share|improve this question
















      /keywordsActions



      import UPDATE_KEYWORDS from "./actionTypes";
      import queryString from "query-string";

      const keywordsArrayFromUrl = () =>
      const query = queryString.parse(window.location.search);
      if (query.keywords)
      const removeDuplicate = new Set(query.keywords.split(" "));
      return Array.from(removeDuplicate);


      return [];
      ;

      export function updateKeywords()
      return async dispatch =>
      dispatch(
      type: UPDATE_KEYWORDS,
      payload: await keywordsArrayFromUrl()
      );
      ;



      /keywordReducer



      import UPDATE_KEYWORDS from "../actions/actionTypes";

      export default function(state = [], action)
      switch (action.type)
      case UPDATE_KEYWORDS:
      return action.payload;
      default:
      return state;




      /SearchBar -- React Component



      import React, Component from "react";
      import withRouter from "react-router-dom";
      //Redux
      import connect from "react-redux";
      import updateKeywords from "../store/actions/KeywordsAction";

      class Searchbar extends Component
      constructor(props)
      super(props);
      this.state =
      keywords : this.props.keywords
      keywordsString: this.props.keywords.join(" ")
      ;


      componentDidMount()
      this.props.updateKeywords();
      console.log(this.props)
      setTimeout(() => console.log(this.props), 10);


      _handleChange = e =>
      this.setState( keywordsString: e.target.value );
      ;

      _handleSearch = value =>
      this.setState( keywordsString: value );
      this.props.history.push(`/search?keywords=$value`);
      ;

      render()
      return (
      <Search
      className="Searchbar"
      placeholder="Cauta prin iBac..."
      value=this.state.keywordsString
      onChange=this._handleChange
      onSearch=this._handleSearch
      />
      );



      const mapStateToProps = state =>
      return
      keywords: state.keywords
      ;
      ;

      export default connect(
      mapStateToProps,
      updateKeywords
      )(withRouter(Searchbar));


      I want to save the keywords from the Url to the store and then pass it to the Search bar state.



      But i dont understand this :



       componentDidMount() 
      this.props.updateKeywords();
      console.log(this.props); // this.props.keywords is empty
      setTimeout(() => console.log(this.props), 10); // After 10 ms this.props.keywords is no empty



      After 10 ms the props of Searchbar gets updated but the component doesn't render again.



      Sorry for my question, I am really new to React / Redux. Please let me know what I am doing wrong. Thank you all!



      Update :



       componentDidMount() 
      this.props.updateKeywords();
      setTimeout(() =>
      this.setState(
      keywordsString: this.props.keywords.join(" ")
      );
      , 0);



      This code is also working... but this other is not working



      componentDidMount() 
      this.props.updateKeywords();
      this.setState(
      keywordsString: this.props.keywords.join(" ")
      );







      reactjs redux react-redux react-thunk






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 27 at 13:34







      Oliu Radu Tudor

















      asked Mar 27 at 13:26









      Oliu Radu TudorOliu Radu Tudor

      62 bronze badges




      62 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          0














          The reason is that componentDidMount is only called once on mount. What you're looking for is either componentShouldUpdate or componentDidUpdate or the render function, all of which are called when your component receives the updated state from redux. You can read here for more information on what these functions do.



          https://reactjs.org/docs/react-component.html#updating






          share|improve this answer

























          • Nope, this doesn't fix it... but thank you for the answer!

            – Oliu Radu Tudor
            Mar 27 at 13:57











          • did you try logging this.props.keywords in your render function? Did it change value?

            – ManavM
            Mar 27 at 14:05










          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%2f55378356%2freact-component-doesnt-update-after-updating-state-with-redux-action%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          The reason is that componentDidMount is only called once on mount. What you're looking for is either componentShouldUpdate or componentDidUpdate or the render function, all of which are called when your component receives the updated state from redux. You can read here for more information on what these functions do.



          https://reactjs.org/docs/react-component.html#updating






          share|improve this answer

























          • Nope, this doesn't fix it... but thank you for the answer!

            – Oliu Radu Tudor
            Mar 27 at 13:57











          • did you try logging this.props.keywords in your render function? Did it change value?

            – ManavM
            Mar 27 at 14:05















          0














          The reason is that componentDidMount is only called once on mount. What you're looking for is either componentShouldUpdate or componentDidUpdate or the render function, all of which are called when your component receives the updated state from redux. You can read here for more information on what these functions do.



          https://reactjs.org/docs/react-component.html#updating






          share|improve this answer

























          • Nope, this doesn't fix it... but thank you for the answer!

            – Oliu Radu Tudor
            Mar 27 at 13:57











          • did you try logging this.props.keywords in your render function? Did it change value?

            – ManavM
            Mar 27 at 14:05













          0












          0








          0







          The reason is that componentDidMount is only called once on mount. What you're looking for is either componentShouldUpdate or componentDidUpdate or the render function, all of which are called when your component receives the updated state from redux. You can read here for more information on what these functions do.



          https://reactjs.org/docs/react-component.html#updating






          share|improve this answer













          The reason is that componentDidMount is only called once on mount. What you're looking for is either componentShouldUpdate or componentDidUpdate or the render function, all of which are called when your component receives the updated state from redux. You can read here for more information on what these functions do.



          https://reactjs.org/docs/react-component.html#updating







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 27 at 13:30









          ManavMManavM

          1,3531 gold badge6 silver badges22 bronze badges




          1,3531 gold badge6 silver badges22 bronze badges















          • Nope, this doesn't fix it... but thank you for the answer!

            – Oliu Radu Tudor
            Mar 27 at 13:57











          • did you try logging this.props.keywords in your render function? Did it change value?

            – ManavM
            Mar 27 at 14:05

















          • Nope, this doesn't fix it... but thank you for the answer!

            – Oliu Radu Tudor
            Mar 27 at 13:57











          • did you try logging this.props.keywords in your render function? Did it change value?

            – ManavM
            Mar 27 at 14:05
















          Nope, this doesn't fix it... but thank you for the answer!

          – Oliu Radu Tudor
          Mar 27 at 13:57





          Nope, this doesn't fix it... but thank you for the answer!

          – Oliu Radu Tudor
          Mar 27 at 13:57













          did you try logging this.props.keywords in your render function? Did it change value?

          – ManavM
          Mar 27 at 14:05





          did you try logging this.props.keywords in your render function? Did it change value?

          – ManavM
          Mar 27 at 14:05






          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          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%2f55378356%2freact-component-doesnt-update-after-updating-state-with-redux-action%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

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현