Create-react-app: Support for class properties ?

Created on 23 Apr 2017  路  5Comments  路  Source: facebook/create-react-app

Sorry if this already has been posted, but i didnot find in issues with keyword "class properties".

My problem is basically at every new project i start with CRA and then starting to right my components, ESLINT complains about unexpected token =.

Thing is i always start implementing my components with :
static propTypes = ...
static defaultProps = ...
static contextTypes = ...
state = { ... }
method = () => { ... }
etc ...

Research told me these are all under the concept of "class-properties", i thought CRA has already included ?

I'm on Windows10, node 7.9.0, CRA 1.3.0, and almost nothing installed globally besides yarn and npm-check.

Do i have to install (or write) something else on top of CRA's base installation ?

question

All 5 comments

This works fine for me, where are you seeing these ESLint errors, in your IDE/text editor or the output from npm start?

You may need to follow the instructions provided here.

in IDE both Webstorm and Atom
but i realized a typo in my report: this isnot Eslint but standard...

i recently removed everything globally installed, including all eslint/babel related stuff

Sorry, we don't support standard. There's not much we can do to help you, unfortunately.
You may be better off asking a question like this on StackOverflow.

I suggest you look prettier if you want to format your code.
If you want to be close to standard, you can add this script to your package.json:

"format": "prettier --single-quote --no-semi --trailing-comma es5 --write 'src/**/*.js'"

Be sure to run npm install prettier --save-dev.

You can format your code on-demand by running npm run format.

If you want to automate this, check out https://github.com/facebookincubator/create-react-app/pull/2006.

If you can figure out how to get standard working, I would be open to a pull request which explains it for people in the future.

I'm going to close this since it's largely unactionable by us, but let me know if you need help getting prettier set up.

mmmm very impresssive, fast formatter.
Thanks for the suggestion ;)

Was this page helpful?
0 / 5 - 0 ratings