bsr bsr - 25 days ago 10
React JSX Question

stateless functional components and `react` import

I face the same issue as described here

So, any file which has only stateless components needs to have

imported like
import React from 'react';
, which is bit annoying (eslint gives error as unused variable; which I understand can be suppressed, still..). Is there a way to avoid having this import in a
based setup.


Answer Source

I had the same issue. Then, I found this:


This will automatically add the required require or import calls to get 'react' imported to your stateless component modules.

P.S. If you use webpack and babel6, ensure that you are not using the jsx-loader for your JSX files. I was getting errors with this and then I realized the jsx-loader is not required anymore. Just use: