1

Sorry for the super newbie vague question, but can I do

import {Component} from 'react'

class MyComponent extends Component { ..

rather than

import * as React from 'react` 

class MyComponent extends React.Component { ..

in babel/webpack/typescript/react ish environment?

If not, why's that?

My webpack.config.json is looking like this.

module: {
  rules: [
    {
      test: /\.js$/,
      use: ['babel-loader', 'source-map-loader'],
      exclude: /node_modules/
    },
    {
      test: /\.tsx?$/,
      exclude: /node_modules/,
      loader: 'happypack/loader?id=ts'
    },

...

plugins: [
  new HappyPack({
    id: 'ts',
    threads: 2,
    loaders: [
      {
        path: 'ts-loader',
        query: { happyPackMode: true }
      }
    ]
  }),

...
Ryo
  • 1,823
  • 3
  • 23
  • 38
  • 1
    This appears to be a duplicate of https://stackoverflow.com/questions/41768205/difference-between-import-react-and-import-component-syntax, which is a duplicate of https://stackoverflow.com/questions/31096597/using-brackets-with-javascript-import-syntax – Chris Sharp Oct 28 '17 at 22:38
  • 1
    What happens if you try...? – Tommi Komulainen Oct 28 '17 at 22:38
  • it shows the message `TS2686: 'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.` – Ryo Oct 28 '17 at 22:42
  • 6
    This is not a duplicate. Typescript, by default, does not allow the named imports to be used with many react packages... – NullVoxPopuli Jun 25 '18 at 14:10

0 Answers0