React native screens with functions or classes?

960 Views Asked by At

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

There are 1 best solutions below

0
On

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