spread operator in react throwing error of Unexpected token

前端 未结 3 577
甜味超标
甜味超标 2020-12-09 16:59

Here is the code where I have included spread operator

style={{ ...styles.detailsRow.icon, alignSelf: \'centre\' }}


What things d

相关标签:
3条回答
  • 2020-12-09 17:24

    You need to configure Babel to use the transform-object-rest-spread plugin. Refer to the following link for details: https://babeljs.io/docs/plugins/transform-object-rest-spread/

    0 讨论(0)
  • 2020-12-09 17:34

    You are missing one babel preset, stage-0

    npm install --save-dev babel-preset-stage-0
    

    if you have .bablerc file add following to it.

    {
      "presets":[
        "es2015", "react", "stage-0"
      ]
    }
    

    Or added to webpack config in loader.

    0 讨论(0)
  • 2020-12-09 17:38

    I had the same problem, and the fix I found was to add experimentalObjectRestSpread to the ecmaFeatures setting in .eslintrc:

    "parserOptions": {
      "ecmaVersion": 6,
      "sourceType": "module",
      "ecmaFeatures": {
         "jsx": true,
         "experimentalObjectRestSpread": true
      }
    }
    
    0 讨论(0)
提交回复
热议问题