Parsing error: Unexpected reserved word 'static'

Mitchell Cartwright

I'm trying to add context to this class component however I am thrown this error.

Do I have a syntax issue or is this a bug?

I'm using it in another component and it is working just fine.

import React, { Component } from 'react'
import { Avatar, Button, CssBaseline, FormControl, FormControlLabel, Checkbox, Input, InputLabel, Paper, Typography, MenuItem, Select } from '@material-ui/core'
import { LockOutlined } from '@material-ui/icons'
import { withStyles } from '@material-ui/core/styles'
import { LanguageContext } from './contexts/LanguageContext'
import styles from './styles/FormStyles'

class Form extends Component {

  render() {
    static contextType = LanguageContext
    const { classes } = this.props



return (
  <main className={classes.main} >
    <Paper className={classes.paper}>
      <Avatar className={classes.avatar}>
        <LockOutlined />
      </Avatar>
      <Typography variant='h5'>Sign In</Typography>
      <Select value='english'>
        <MenuItem value='english'>English</MenuItem>
        <MenuItem value='french'>French</MenuItem>
        <MenuItem value='spanish'>Spanish</MenuItem>
      </Select>
      <form className={classes.form}>
        <FormControl margin='normal' required fullWidth>
          <InputLabel htmlFor='email'>Email</InputLabel>
          <Input id='email' name='email' autoFocus />
        </FormControl>
        <FormControl margin='normal' required fullWidth>
          <InputLabel htmlFor='password'>Password</InputLabel>
          <Input id='password' name='password' autoFocus />
        </FormControl>
        <FormControlLabel control={<Checkbox color='primary' />} label='Remember Me'></FormControlLabel>
        <Button variant='contained' type='submit' fullWidth color='primary' className={classes.submit}>Sign In</Button>
      </form>
    </Paper>
  </main>
)
  }
}

export default withStyles(styles)(Form)
aeXuser264

The problem is here,

render() {
    static contextType = LanguageContext // <- here
    const { classes } = this.props

You cant use static in there, instead you probably wanted to use it in class, Just shift it in the class and it will work,

class ... {
  static contextType = LanguageContext
...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I fix error: "Parsing error: Unexpected reserved word 'await'. (10:22)eslint"?

Unexpected reserved word error using Jest

TypeScript: Unexpected reserved word

Unexpected reserved word 'await'

Jint "unexpected reserved word"

Can I ignore Unexpected reserved word error by eslint-loader

SyntaxError: Unexpected reserved word on typescript

SyntaxError: Unexpected reserved word "await"

Is 'err' a reserved word for an error?

Parsing error: The keyword 'interface' is reserved

Unexpected reserved word 'await' for react native

Meteor 1.3 NPM: Unexpected reserved word import

Unexpected reserved word 'import' when using babel

unexpected reserved word import in node.js

SyntaxError: unexpected reserved word 'await' in async function

SyntaxError: Unexpected reserved word, for await loop

Unexpected use of reserved word 'let' in strict mode

SyntaxError: Unexpected reserved word on running mocha with enzyme

Firestore: Uncaught SyntaxError: Unexpected reserved word

Unexpected reserved word 'await' in getting the session id

Unexpected reserved word 'await' in async function in react

React JS Unexpected reserved word 'await'

Uncaught SyntaxError: Unexpected reserved word in a {name} file

Error in StackBlitz: 'Unexpected strict mode reserved word' trying to use async/await with subscription.toPromise()

eslint: error Parsing error: The keyword 'const' is reserved

error parsing 'Gemfile', unexpected <<,

eslint. Parsing error: The keyword 'interface' is reserved

Javascript Parsing error : Unexpected Error

SyntaxError: Unexpected reserved word => prettier/third-party.js