1

I'm trying to use navigationOptions but reactNative doesn't recognize "static".

I've tried with classes and it worked, but with the function it didn't work

export default function Home() {
  static navigationOptions = {
    title: 'Home',
  };
  return (
    <View style={styles.container}>
      <Text style={styles.h1}>Home</Text>
    </View>
  );
}

Uncaught (in promise) TypeError: Cannot read property 'concat' of undefined
    at DeltaPatcher.applyDelta (DeltaPatcher.js:77)
    at deltaUrlToBlobUrl (deltaUrlToBlobUrl.js:28)
    at async getBlobUrl ((index):237)
    at async WebSocket.ws.onmessage ((index):192)
1
  • 1
    Home is a function, not a class. Commented Aug 24, 2019 at 21:04

1 Answer 1

2

In your example, you can create a static variable shared by all instances like this:

export default function Home() {
  return (
    <View style={styles.container}>
      <Text style={styles.h1}>Home</Text>
    </View>
  );
}

Home.navigationOptions = {
  title: 'Home',
};

In JavaScript functions are first-class objects. So being an object, you can assign properties to a function.

In ES6 the class keyword was introduced with an accompanied static keyword.

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.