简体   繁体   中英

The react-select module cannot find react

React-select cannot find React: TypeError: React is undefined1 react-select.js:826:4

React-select.js is getting react through

var React = (window.React);

It lookes like i have to include React in the html to make this work, but i would like to avoid this. Is there something i am missing?

(using node)

Let me guess, you require dist/react-select.js . This script is used for browser environment. Try to require node environment script, which described in package.json . Or if you use npm install react-select it enough to call require('react-select');

We need some more clarification here, "using node" - are you rendering on node server?

If you are rendering in the client/browser, var React = (window.React); can possibly be called before window.React is available...

I recommend using commonJs pattern ie: var React = require('React');

I hope my answer will solve some of your issues with React. To start off, React is not the most 'noob' frendily 'View'(MVC).

I personally believe that HTML should only handle any Javascript. Let's separate the concerns into two.


|-- index.html

|-- app.js

Now, we have two files with two separate concerns. I do agree that the proper way to 'requiring' <== current way || 'import' new ES6way (AS of Release of Node 6) but for the simplicity sake, let's use CDNs. Add these script tags

<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.0.2/react.min.js'></script>

    <script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.0.2/react-dom.min.js'> </script> 

"Keep clam =*= solve bugs"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM