简体   繁体   中英

React - Eslint - Camel camel case props

I have a question about a standard eslint and camel case. I have a redundant error on this type of code.

const response = yield call(currentAccount, localStorage.getItem('auth_token'))
  console.log(`RESPONSE ${JSON.stringify(response)}`)


  if (response) {
    const { id, email, first_name, last_name, name } = response

    yield put({
      type: 'user/SET_STATE',
      payload: {
        id,
        name,
        email,
        authorized: true,
        lastname: last_name,
        firstname: fist_name
      },
    })
  } 

Line 53: Identifier 'first_name' is not in camel case camelcase

How can I fix this error without disabling esLint on this type of formatting?

Thanks a lot

In your file you can add a comment like

/*eslint camelcase: ["error", {allow: ["first_name"]}]*/

Or you can configure camelcase rule in your.eslintrc

camelcase: ["error", {allow: ["first_name"]}]

You can assign different variable names when destructuring:

const { id, email, first_name: fistName, last_name: lastName, name } = response

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM