Skip to content
Advertisement

how to update the state before rendering the component?

I have this app that adds “persons” to a “phonebook”, and the user can update the person’s phone if the person already exists. but I want to know to handle the problem of when the person was already deleted (i open two tabs and delete a phone in one tab, and I try to “update” it in the second tab)

I have a persons.js which handles all HTTP requests (I’m using axios) and a PersonNotification.js which tell the user if the phone is “added” or “updated” or “doesn’t exist anymore” and all the main functionalities are inside the App.js

here is my code

persons.js

JavaScript

App.js

JavaScript

PersonNotification.js

JavaScript

PS: this the github folder of this app. this is an exercise from fullstackopen.com so i hesitate a bit before posting my question here, but i spent more than 4 hours on this problem all i want is to figure out how to update the state of “errMsg” earlier, and i think after that everything will become easy

Advertisement

Answer

This part should help you enough to go further.

persons.js

JavaScript

App.js

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement