React/Redux - How to call an action after component has rendered, based on a check - Getting errorHow to dispatch a Redux action with a timeout?What is mapDispatchToProps?How to dispatch Redux action from stateless component when route is loaded?Reducers state update not calling render function of parent component . React/ReduxReact, redux component does not update on route changeReact-Redux / Child component not re-renderingReactJS + Redux: Infinite render loop with (functional) Component wrapper + dispatch (state) in child ComponentReact Component render not called first time with reduxreact wait for component to get state from store then render childDispatching Redux actions on location change with react-router-dom
How to give my students a straightedge instead of a ruler
What the did the controller say during my approach to land (audio clip)?
Madrid to London w/ Expired 90/180 days stay as US citizen
Preventing the ears from getting clogged on descent to Barcelona
Can we have a C++ function with multiple return types? ( C++11 and above)
Delete empty subfolders, keep parent folder
Are there any instances in Tanach of Lashon Hara said purely for non-constructive purposes?
Do household ovens ventilate heat to the outdoors?
Why do things cool off?
Statistical tests for benchmark comparison
Why is belonging not transitive?
How is underwater propagation of sound possible?
How would you design and build an American Civil War Steam Gun?
SQL Server Always-On Availability Groups Patching
Social Encounters in a West Marches Campaign
Is Yang not precluded from conduting his "UBI experiment" as an electoral candidate?
What can I actually do with a high credit score?
Applications of mathematics in clinical setting
What is the word for a person who destroys monuments?
Secondary characters in character-study fiction
Who are the people reviewing far more papers than they're submitting for review?
Microservices and Stored Procedures
Why would a fighter use the afterburner and air brakes at the same time?
Why are two-stroke engines nearly unheard of in aviation?
React/Redux - How to call an action after component has rendered, based on a check - Getting error
How to dispatch a Redux action with a timeout?What is mapDispatchToProps?How to dispatch Redux action from stateless component when route is loaded?Reducers state update not calling render function of parent component . React/ReduxReact, redux component does not update on route changeReact-Redux / Child component not re-renderingReactJS + Redux: Infinite render loop with (functional) Component wrapper + dispatch (state) in child ComponentReact Component render not called first time with reduxreact wait for component to get state from store then render childDispatching Redux actions on location change with react-router-dom
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have, what should be a simple issue in which, when a user navigates to a specific route, the component fires an initial function call to grab a user by ID via a redux-observable
in an epic. However, if the user navigates away from the page and then comes back, I need to be able to reload the page, based on a route parameter.
I have a component that utilizes an HOC to run the render() method, but it looks like a dumb component:
const ProfilePage = props =>
const actions, user, loading = props;
// Note: This if statement results in an error
if (user && user.id !== props.params.id)
actions.initAction(props.params.id);
return (<div>Test</div>);
;
ProfilePage.propTypes =
actions: PropTypes.object,
user: PropTypes.object,
loading: PropTypes.bool,
;
export default connect(
state => (
user: selectUser(state),
loading: selectLoading(state),
),
dispatch => ( actions: bindActionCreators(Actions, dispatch) )
)(
PureRender(
onMount(props => props.actions.initAction(props.params.id))(ProfilePage)
)
);
This results in an error:
react-dom.development.js?61bb:506 Warning: Cannot update during an existing state transition (such as within
render). Render methods should be a pure function of props and state.
^ This happens because of my if
statement that checks the user id against the params id.
Does this component need to be converted into a class in order to utilize other life cycle methods that could prevent this error from happening and run my functionality accordingly?
reactjs redux react-redux redux-observable
add a comment
|
I have, what should be a simple issue in which, when a user navigates to a specific route, the component fires an initial function call to grab a user by ID via a redux-observable
in an epic. However, if the user navigates away from the page and then comes back, I need to be able to reload the page, based on a route parameter.
I have a component that utilizes an HOC to run the render() method, but it looks like a dumb component:
const ProfilePage = props =>
const actions, user, loading = props;
// Note: This if statement results in an error
if (user && user.id !== props.params.id)
actions.initAction(props.params.id);
return (<div>Test</div>);
;
ProfilePage.propTypes =
actions: PropTypes.object,
user: PropTypes.object,
loading: PropTypes.bool,
;
export default connect(
state => (
user: selectUser(state),
loading: selectLoading(state),
),
dispatch => ( actions: bindActionCreators(Actions, dispatch) )
)(
PureRender(
onMount(props => props.actions.initAction(props.params.id))(ProfilePage)
)
);
This results in an error:
react-dom.development.js?61bb:506 Warning: Cannot update during an existing state transition (such as within
render). Render methods should be a pure function of props and state.
^ This happens because of my if
statement that checks the user id against the params id.
Does this component need to be converted into a class in order to utilize other life cycle methods that could prevent this error from happening and run my functionality accordingly?
reactjs redux react-redux redux-observable
add a comment
|
I have, what should be a simple issue in which, when a user navigates to a specific route, the component fires an initial function call to grab a user by ID via a redux-observable
in an epic. However, if the user navigates away from the page and then comes back, I need to be able to reload the page, based on a route parameter.
I have a component that utilizes an HOC to run the render() method, but it looks like a dumb component:
const ProfilePage = props =>
const actions, user, loading = props;
// Note: This if statement results in an error
if (user && user.id !== props.params.id)
actions.initAction(props.params.id);
return (<div>Test</div>);
;
ProfilePage.propTypes =
actions: PropTypes.object,
user: PropTypes.object,
loading: PropTypes.bool,
;
export default connect(
state => (
user: selectUser(state),
loading: selectLoading(state),
),
dispatch => ( actions: bindActionCreators(Actions, dispatch) )
)(
PureRender(
onMount(props => props.actions.initAction(props.params.id))(ProfilePage)
)
);
This results in an error:
react-dom.development.js?61bb:506 Warning: Cannot update during an existing state transition (such as within
render). Render methods should be a pure function of props and state.
^ This happens because of my if
statement that checks the user id against the params id.
Does this component need to be converted into a class in order to utilize other life cycle methods that could prevent this error from happening and run my functionality accordingly?
reactjs redux react-redux redux-observable
I have, what should be a simple issue in which, when a user navigates to a specific route, the component fires an initial function call to grab a user by ID via a redux-observable
in an epic. However, if the user navigates away from the page and then comes back, I need to be able to reload the page, based on a route parameter.
I have a component that utilizes an HOC to run the render() method, but it looks like a dumb component:
const ProfilePage = props =>
const actions, user, loading = props;
// Note: This if statement results in an error
if (user && user.id !== props.params.id)
actions.initAction(props.params.id);
return (<div>Test</div>);
;
ProfilePage.propTypes =
actions: PropTypes.object,
user: PropTypes.object,
loading: PropTypes.bool,
;
export default connect(
state => (
user: selectUser(state),
loading: selectLoading(state),
),
dispatch => ( actions: bindActionCreators(Actions, dispatch) )
)(
PureRender(
onMount(props => props.actions.initAction(props.params.id))(ProfilePage)
)
);
This results in an error:
react-dom.development.js?61bb:506 Warning: Cannot update during an existing state transition (such as within
render). Render methods should be a pure function of props and state.
^ This happens because of my if
statement that checks the user id against the params id.
Does this component need to be converted into a class in order to utilize other life cycle methods that could prevent this error from happening and run my functionality accordingly?
reactjs redux react-redux redux-observable
reactjs redux react-redux redux-observable
asked Mar 28 at 13:37
Stevie StarStevie Star
1,09517 silver badges34 bronze badges
1,09517 silver badges34 bronze badges
add a comment
|
add a comment
|
2 Answers
2
active
oldest
votes
Function component should be pure, you can think of them as the "render" method of a class component.
You can either use a class component and do side effects in componentDidMount
/ componentDidUpdate
, or use hooks with useEffect
.
hooks useEffect / class cycle methods
add a comment
|
I am guessing the issue is with ProfilePage
. Added error Cannot update during an existing state transition (such as withinrender).
thrown mostly when a setState which is a async method, another setState gets called. For your case it's a functional component which you are using it in render method. So basically each time your component rerenders ProfilePage function gets called which calls the action. So you might wanna change ProfilePage this to a react component and use life cycle methods such as componentDidMount
to fix your issue.
Or if you are using react 16 or above use hooks with useEffect.
This did the trick withuseEffect
. Is there a downside to using this? Some of the other responses seem to say so
– Stevie Star
Mar 28 at 13:57
If I had to quote from react documentation, Yes! By default, it runs both after the first render and after every update. But you use it right, wouldn't be an issue. Read reactjs.org/docs/… also from a maintainable perspective, componentDidMount and other life cycles methos are very popular so oher developers are well aware of this. This is a bit new. So you might wanna think about the maintainability. Others no issues to use it if you are using it right.
– Subhendu Kundu
Mar 28 at 14:03
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/4.0/"u003ecc by-sa 4.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%2f55399009%2freact-redux-how-to-call-an-action-after-component-has-rendered-based-on-a-che%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Function component should be pure, you can think of them as the "render" method of a class component.
You can either use a class component and do side effects in componentDidMount
/ componentDidUpdate
, or use hooks with useEffect
.
hooks useEffect / class cycle methods
add a comment
|
Function component should be pure, you can think of them as the "render" method of a class component.
You can either use a class component and do side effects in componentDidMount
/ componentDidUpdate
, or use hooks with useEffect
.
hooks useEffect / class cycle methods
add a comment
|
Function component should be pure, you can think of them as the "render" method of a class component.
You can either use a class component and do side effects in componentDidMount
/ componentDidUpdate
, or use hooks with useEffect
.
hooks useEffect / class cycle methods
Function component should be pure, you can think of them as the "render" method of a class component.
You can either use a class component and do side effects in componentDidMount
/ componentDidUpdate
, or use hooks with useEffect
.
hooks useEffect / class cycle methods
answered Mar 28 at 13:49
Sagiv b.gSagiv b.g
19.8k6 gold badges30 silver badges65 bronze badges
19.8k6 gold badges30 silver badges65 bronze badges
add a comment
|
add a comment
|
I am guessing the issue is with ProfilePage
. Added error Cannot update during an existing state transition (such as withinrender).
thrown mostly when a setState which is a async method, another setState gets called. For your case it's a functional component which you are using it in render method. So basically each time your component rerenders ProfilePage function gets called which calls the action. So you might wanna change ProfilePage this to a react component and use life cycle methods such as componentDidMount
to fix your issue.
Or if you are using react 16 or above use hooks with useEffect.
This did the trick withuseEffect
. Is there a downside to using this? Some of the other responses seem to say so
– Stevie Star
Mar 28 at 13:57
If I had to quote from react documentation, Yes! By default, it runs both after the first render and after every update. But you use it right, wouldn't be an issue. Read reactjs.org/docs/… also from a maintainable perspective, componentDidMount and other life cycles methos are very popular so oher developers are well aware of this. This is a bit new. So you might wanna think about the maintainability. Others no issues to use it if you are using it right.
– Subhendu Kundu
Mar 28 at 14:03
add a comment
|
I am guessing the issue is with ProfilePage
. Added error Cannot update during an existing state transition (such as withinrender).
thrown mostly when a setState which is a async method, another setState gets called. For your case it's a functional component which you are using it in render method. So basically each time your component rerenders ProfilePage function gets called which calls the action. So you might wanna change ProfilePage this to a react component and use life cycle methods such as componentDidMount
to fix your issue.
Or if you are using react 16 or above use hooks with useEffect.
This did the trick withuseEffect
. Is there a downside to using this? Some of the other responses seem to say so
– Stevie Star
Mar 28 at 13:57
If I had to quote from react documentation, Yes! By default, it runs both after the first render and after every update. But you use it right, wouldn't be an issue. Read reactjs.org/docs/… also from a maintainable perspective, componentDidMount and other life cycles methos are very popular so oher developers are well aware of this. This is a bit new. So you might wanna think about the maintainability. Others no issues to use it if you are using it right.
– Subhendu Kundu
Mar 28 at 14:03
add a comment
|
I am guessing the issue is with ProfilePage
. Added error Cannot update during an existing state transition (such as withinrender).
thrown mostly when a setState which is a async method, another setState gets called. For your case it's a functional component which you are using it in render method. So basically each time your component rerenders ProfilePage function gets called which calls the action. So you might wanna change ProfilePage this to a react component and use life cycle methods such as componentDidMount
to fix your issue.
Or if you are using react 16 or above use hooks with useEffect.
I am guessing the issue is with ProfilePage
. Added error Cannot update during an existing state transition (such as withinrender).
thrown mostly when a setState which is a async method, another setState gets called. For your case it's a functional component which you are using it in render method. So basically each time your component rerenders ProfilePage function gets called which calls the action. So you might wanna change ProfilePage this to a react component and use life cycle methods such as componentDidMount
to fix your issue.
Or if you are using react 16 or above use hooks with useEffect.
answered Mar 28 at 13:52
Subhendu KunduSubhendu Kundu
1,6791 gold badge7 silver badges24 bronze badges
1,6791 gold badge7 silver badges24 bronze badges
This did the trick withuseEffect
. Is there a downside to using this? Some of the other responses seem to say so
– Stevie Star
Mar 28 at 13:57
If I had to quote from react documentation, Yes! By default, it runs both after the first render and after every update. But you use it right, wouldn't be an issue. Read reactjs.org/docs/… also from a maintainable perspective, componentDidMount and other life cycles methos are very popular so oher developers are well aware of this. This is a bit new. So you might wanna think about the maintainability. Others no issues to use it if you are using it right.
– Subhendu Kundu
Mar 28 at 14:03
add a comment
|
This did the trick withuseEffect
. Is there a downside to using this? Some of the other responses seem to say so
– Stevie Star
Mar 28 at 13:57
If I had to quote from react documentation, Yes! By default, it runs both after the first render and after every update. But you use it right, wouldn't be an issue. Read reactjs.org/docs/… also from a maintainable perspective, componentDidMount and other life cycles methos are very popular so oher developers are well aware of this. This is a bit new. So you might wanna think about the maintainability. Others no issues to use it if you are using it right.
– Subhendu Kundu
Mar 28 at 14:03
This did the trick with
useEffect
. Is there a downside to using this? Some of the other responses seem to say so– Stevie Star
Mar 28 at 13:57
This did the trick with
useEffect
. Is there a downside to using this? Some of the other responses seem to say so– Stevie Star
Mar 28 at 13:57
If I had to quote from react documentation, Yes! By default, it runs both after the first render and after every update. But you use it right, wouldn't be an issue. Read reactjs.org/docs/… also from a maintainable perspective, componentDidMount and other life cycles methos are very popular so oher developers are well aware of this. This is a bit new. So you might wanna think about the maintainability. Others no issues to use it if you are using it right.
– Subhendu Kundu
Mar 28 at 14:03
If I had to quote from react documentation, Yes! By default, it runs both after the first render and after every update. But you use it right, wouldn't be an issue. Read reactjs.org/docs/… also from a maintainable perspective, componentDidMount and other life cycles methos are very popular so oher developers are well aware of this. This is a bit new. So you might wanna think about the maintainability. Others no issues to use it if you are using it right.
– Subhendu Kundu
Mar 28 at 14:03
add a comment
|
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%2f55399009%2freact-redux-how-to-call-an-action-after-component-has-rendered-based-on-a-che%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