javascript - static 是严格模式的保留关键字

标签 javascript react-native

我试图在 ReactNative 中声明一个静态变量,但当我收到此错误消息时,我似乎无法让它工作:

SyntaxError: /Users/vikaton/Desktop/iComeUp/src/components/LoginForm.js: static is a reserved word in strict mode (74:4)
9:37:20 PM:   72 | 
9:37:20 PM:   73 |   render() {
9:37:20 PM: > 74 |     static navigationOptions = {
9:37:20 PM:      |     ^
9:37:20 PM:   75 |       header: null
9:37:20 PM:   76 |     };
9:37:20 PM:   77 |     const { navigate } = this.props.navigation // fontFamily: 'heiti TC'

我在代码顶部添加了 'use strict'; 但仍然收到错误消息。

有什么指点吗?

最佳答案

您希望静态位于 render 方法之外,而不是内部

   static navigationOptions = { header: null }

   render() {
      const { navigate } = this.props.navigation
      ...
   }

关于javascript - static 是严格模式的保留关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48180866/

相关文章:

android - 找不到兼容的并排 NDK 版本 React Native

javascript - jQuery UI slider : access options from function associated with the slide event

reactjs - React-Native : How to get callback of api call in another class

react-native - 在 React Native 中,如何将一个 View 放在另一个 View 之上,并且其中一部分位于后面 View 的边界之外?

macos - 如何让react-native run-ios在iTerm而不是macOS上的终端中打开?

android - 在使用 Android 模拟器启动应用程序时 react native 错误

javascript - Angular 2 组件变量范围和引用

JavaScript with Ajax with HTTP request outputs undefined display 2

javascript - 如何从 dojo 中的 FilteringSelect 获取所有值?

javascript - 使用 Yup 和 Typescript 的动态验证消息