簡體   English   中英

React Native無法識別靜態變量

[英]React native does not recognize static variable

我正在嘗試使用navigationOptions,但reactNative無法識別“靜態”。

我已經嘗試過使用類,並且可以使用,但是不能使用功能

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)

在您的示例中,您可以創建一個由所有實例共享的靜態變量,如下所示:

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

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

在JavaScript中,函數是一流的對象。 因此,作為對象,您可以將屬性分配給函數。

在ES6中,class關鍵字與伴隨的static關鍵字一起引入。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM