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;
/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
add a comment |
/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
add a comment |
/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
/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
reactjs redux react-redux react-thunk
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
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
Nope, this doesn't fix it... but thank you for the answer!
– Oliu Radu Tudor
Mar 27 at 13:57
did you try loggingthis.props.keywords
in your render function? Did it change value?
– ManavM
Mar 27 at 14:05
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
Nope, this doesn't fix it... but thank you for the answer!
– Oliu Radu Tudor
Mar 27 at 13:57
did you try loggingthis.props.keywords
in your render function? Did it change value?
– ManavM
Mar 27 at 14:05
add a comment |
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
Nope, this doesn't fix it... but thank you for the answer!
– Oliu Radu Tudor
Mar 27 at 13:57
did you try loggingthis.props.keywords
in your render function? Did it change value?
– ManavM
Mar 27 at 14:05
add a comment |
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
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
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 loggingthis.props.keywords
in your render function? Did it change value?
– ManavM
Mar 27 at 14:05
add a comment |
Nope, this doesn't fix it... but thank you for the answer!
– Oliu Radu Tudor
Mar 27 at 13:57
did you try loggingthis.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
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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