Message from JavaScript discussions

March 2019

— I’m trying to replicate your component in a sandbox but you make this hard without providing the sandbox by yourself.
The other thing is on your method componentDidMount you’re calling directly the action creator, not the connected one. You have to use this.props.fetchSingleMasterAgent in order to use the connected with your redux one.

Message permanent page


Yes. I did that because when I refresh the edit form page I lose the content in the redux store thereby losing the user details that was initially populated in the form . But I have removed the componentDidMount() but I still get the same result.. The form is not editable but it is populated with the user details. But now since I have removed componentDidMount once I refresh the edit page i loose the values that was initially populated on the form

— How do you mean when you say "making it hard without providing sandbox"? please lemme know in any way i can make it easy?

Message permanent page

— Yes, like a

— Alpha beta omega

— udval15 I found the problem.
> getDerivedStateFromProps is invoked right before calling the render method, both on the initial mount and on subsequent updates.

This means your state are being overwritten every render by the contents of your props.

Message permanent page

— Please what do I do to solve this?

— You will need to know if those props were used already

— How? is there an example i can follow I am still new using react.

— Add something like this


state = {
singleMasterAgent: null
static getDerivedStateFromProps(nextProps) {
if (nextProps.singleMasterAgent === nextProps.singleMasterAgent) return null
return {
singleMasterAgent: nextProps.singleMasterAgent

Message permanent page

— udval15 ^