Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React Native: Is it possible to call a function directly without any button press or TouchableOpacity?

I want to call a function on the second screen as soon as the screen navigates to the second screen. Is it possible?

This is related to firebase phone auth but here the OTP screen is on another screen not on the same screen.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

on the screen, you can use useEffect to call a function on load or when a prop changes.

e.g. if you just want to load it once when page renders:

const getMyStuffFromTheApi = () => {
  //TODO
}

React.useEffect(() => {
 getMyStuffFromTheApi();
}, []);

e.g.2 if you want to call the function every time the prop changes

const getMyStuffFromTheApi = () => {
  //TODO
}

React.useEffect(() => {
 getMyStuffFromTheApi();
}, [yourProp]);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading