Topic: Changed Name is not reflected in Top Navigation
rashesh patel free asked 4 years 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 4 years 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 free commented 4 years 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 4 years ago
It does mean you have an infinite loop. You have to try to resolve this with another if/else conditions.
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Free
- Premium support: No
- Technology: MDB React
- MDB Version: 4.18.1
- Device: Laptop
- Browser: Chrome
- OS: Windows 10
- Provided sample code: No
- Provided link: No
Piotr Glejzer staff commented 4 years ago
Did you try use componentdidupdate/useeffect?
rashesh patel free commented 4 years ago
Hi Piotr
Can you give me some example for the same?
Piotr Glejzer staff commented 4 years ago
Yes, sure but do you have an example code to show me?
rashesh patel free commented 4 years ago
Hi Piotr,
Please refer below snippet link https://mdbootstrap.com/snippets/react/rashesh_patel/1877120
Thank you.