1

I created a new React Native CLI project and was thinking to convert the App component to a class based component to fix a hot reload issue when using react-navigation.

But I don't understand the logic with these two arrow functions, and how to convert it:

const App: () => React$Node = () => {
  return <NavigationWrapper />;
};

Update: the arrow question was answered, though it didn´t help for the hot reload issue (a glitch in my logic there). See this link for a solution for that.

1 Answer 1

2

First, be very careful when reading this code. It looks like two arrow functions, but actually the second 'arrow function' is the type annotation of App. So it's the same as this:

const App: (() => React$Node) = () => {
  return <NavigationWrapper />;
};

or even clearer:

const App = (): React$Node => {
  return <NavigationWrapper />;
};

Then, remember that arrow functions are just like regular functions, so this can be written like so:

function App(): React$Node {
  return <NavigationWrapper />;
};

So now it becomes pretty clear how this might look:

class App {
  render(): React$Node {
    return <NavigationWrapper />;
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! Time for me to dive deeper into the type universe. The class example works except that I had to remove the public keyword.
Oh right, render wouldn't be public. Don't forget to accept the answer if this solved your problem!

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.