Here's a dirty hack to avoid importing React in every file with JSX. Just add React to window before ReactDOM.render.
ReactDOM.render
import ReactDOM from 'react-dom'; import React from 'react'; import App from './App'; window.React = React; ReactDOM.render(<App/>, document.querySelector('#mount'));
Now App.js works without throwing a React is not defined error.
React is not defined
// App.js export default function() { return <div>I am App!</div> }
This hack is just to illustrate React dependency management. Don't use it in the production code! 😄
Holy mate... Such a convinient hack... You spoiled me 😂
Tried here and worked
yeep that should do the trick :D, by putting React to the global window object
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here's a dirty hack to avoid importing React in every file with JSX. Just add React to window before
ReactDOM.render
.Now App.js works without throwing a
React is not defined
error.This hack is just to illustrate React dependency management. Don't use it in the production code! 😄
Holy mate... Such a convinient hack... You spoiled me 😂
Tried here and worked
yeep that should do the trick :D, by putting React to the global window object