N
N
Newbie Ivanovich2019-07-30 05:57:24
React Native
Newbie Ivanovich, 2019-07-30 05:57:24

How to run componentdidmount after navigating from another screen back to home screen?

I change the profile data in a separate screen, then I go back to the profile screen, but the profile has not been updated and displays the old information.
made a button that updates/loads data from the server.
how to do it without pressing the button?
now the data is loaded in componentDidMount.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Alexandrovich, 2019-07-30
@NovichokIvanovich

Novice Ivanovich , you have 2 exits
1 after Changing the profile data and pressing back, you send the corrected data on the server and simply substitute the new data in the profile page (so you do not need to make 1 more request from the server, but not the fact that the change request will be successful)
2 you change the profile data, for example, click save the changed data (there is a request to the server), then you press the back button. Here you have several options and in each of them you re-request the data from the server so that they are updated to be displayed in the profile
in componentWillUnmount, you can put the request function
on the save changes button, first the request to change the data will pass, then call the function that
will update the profile data and redirect the user to the screen you need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question