Vladimir37 Vladimir37 - 10 days ago 5
Javascript Question

React in WebPack

I join JS-files through WebPack. In config introduced all files.

entry: ['./file1', './file2', 'react', 'react-dom']


React and React-dom downloaded through npm. If in file I call React, returns error:

ReferenceError: React is not defined


But if I write

import {React} from 'react';


returns error

TypeError: _react.React is undefined


What am I doing wrong?

Answer

It should be like,

import React from 'react';
import ReactDOM from 'react-dom';

ReactDOM.render(...);
Comments