Message from JavaScript discussions

March 2019

— 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.

— 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 ^

— Okay lemme try that

— Wow this works... thank you!

— Glad to help you. 😊

— Please will you advice I use only the connected props from redux? and is it okay to loose the populated field when I refresh the edit form page? I am asking because I trying to know what the best practices are

Message permanent page