Topic: Changed Name is not reflected in Top Navigation
rashesh patel
asked a year ago
Hi,
In Top Navigation I just show the Organization name using code:
{this.state.organizationName}
When I am trying to Edit that Organization name in its Edit profile, it Edited in the database but at the same time edited name is not reflected on Top Navigation.
So what should I do for that?
Piotr Glejzer
staff answered a year ago
Did you try to use something like this?
componentDidUpdate(prevState){
if(prevState.organizationName !== this.state.organizationName){
this.setState({organizationName: this.state.organizationName})
}
}
rashesh patel commented 8 months ago
Hi Piotr, I used
componentDidUpdate(prevState){ if(prevState.organizationName !== this.state.organizationName){ this.setState({organizationName: this.state.organizationName}) } }
but error comes "Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops."
Piotr Glejzer staff commented 8 months ago
It does mean you have an infinite loop. You have to try to resolve this with another if/else conditions.
Answered
- User: Free
- Premium support: No
- Technology: React
- MDB Version: 4.18.1
- Device: Laptop
- Browser: Chrome
- OS: Windows 10
- Provided sample code: No
- Provided link: No
Piotr Glejzer staff commented a year ago
Did you try use componentdidupdate/useeffect?
rashesh patel commented a year ago
Hi Piotr
Can you give me some example for the same?
Piotr Glejzer staff commented a year ago
Yes, sure but do you have an example code to show me?
rashesh patel commented a year ago
Hi Piotr,
Please refer below snippet link https://mdbootstrap.com/snippets/react/rashesh_patel/1877120
Thank you.