Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

317
Views
Can't use fat arrow functions (ES6) in react

I've had some issues using fat arrow functions in react. If the function is not anonymous, it complains about the syntax and won't compile.

This:

handleItemClick = (e, { name }) => this.setState({ activeItem: name });

Gives me:

BabelLoaderError: SyntaxError: Unexpected token (20:20)

It points to the equal sign(handleItemClick'=').

This however works just fine:

onClick={ (arg) => {//Do something} };

Is there something wrong with my webpack config, or something else i'm missing? Thankful for any hints.

module.exports = {
  entry: PATHS.app_path,
    output:{
        path: PATHS.build,
        filename: 'index.js'
    },
    devServer:{
        inline: true,
        port: 3333,
        contentBase: PATHS.build,
        publicBase: PATHS.build,
        historyApiFallback: true
    },
    resolve: {
        root: path.resolve('./public'),
        extensions: ['', '.js', '.jsx']
    },
    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                exclude: /(node_modules|bower_components)/,
                loader: 'babel',
                query: {
                    presets: ['es2015', 'react']
                }
            },
            {
                test: /\.css$/,
                loader: 'style-loader'
            },
            {
                test: /\.css$/,
                loader: 'css-loader',
                query: {
                    modules: true,
                    localIdentName: '[local]'
                    //localIdentName: '[name]__[local]___[hash:base64:5]'
                }
            },
            { test: /\.(png|woff|woff2|eot|ttf|jpg)$/, loader: 'url-loader?limit=100000' },
            {
                test: /.*\.svg$/,
                loaders: [
                    'file-loader',
                    'svgo-loader?' + svgoConfig,
                ]
            }
        ]
    }
};
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You are trying to use class fields, which are not part of ES6, and aren't covered by es2015, and react presets.

You can enable it by using the Class properties transform babel plugin:

query: {
    presets: ['es2015', 'react'],
    plugins: ["transform-class-properties"]
}   

Or use the babel stage-2 preset, that includes the transform plugin:

query: {
    presets: ['es2015', 'react', 'stage-2']
}

Don't forget to npm install the one that you choose.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!