0

I'm making an app with react native, actually I have the screens with classes :

class registerScreen extends Component {

But now I'll like to use "useEffect" hook but see I cannot with classes so I have to migrate them to functions...something like...

const registerScreen = () => {

which is the correct or best practice method? What about the constructor and componentDidMount(), etc...

In the other hand it's possible to use the "useEffect" hook on a screen made with a class? How?

Thanks

1 Answer 1

2

React Native Official documents says if you're going to develop a new react native app use functional component and hooks instead using class component.If you already developed your app using class components it's okay,

useEffect() is same as like compnentDidMount(). So In there you call axios or fetch request, load asnyc storage data etc.

You can't use useEffect() in your class components you can use componentWillMount(), componentDidUpdate(), etc.

please refer following official document for more info, https://reactnative.dev/docs/getting-started

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.