Answer the question
In order to leave comments, you need to log in
Why does the directive throw an error (React + TS)?
Hello.
In Of. doc-tion
there is such a recommendation as
// When importing a module whose path matches one of the following, just
// assume a corresponding global variable exists and use that instead.
// This is important because it allows us to avoid bundling all of our
// dependencies, which allows browsers to cache those libraries between builds.
externals: {
"react": "React",
"react-dom": "ReactDOM"
}
React is not defined
import * as React from 'react';
import React from 'react';
Answer the question
In order to leave comments, you need to log in
1. In this case, React must be connected to the page with an external library. For example like this:
<script crossorigin src="https://unpkg.com/[email protected]/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/[email protected]/umd/react-dom.production.min.js"></script>
import React, { useContext } from 'react';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question