-
Notifications
You must be signed in to change notification settings - Fork 759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React-rails with react-select #437
Comments
@CostaRico You are probably adding multiple versions of react source? Please check react-select module and also you are not loading react via Sprockets. |
@gauravtiwari I've removed it, now my files looks like: application.js //= require jquery
//= require jquery_ujs
//= require react
//= require react_ujs
//= require components
//= require utils/functions
//= require_tree .
//= require bootstrap-sprockets And components.js //= require_tree ./components
Functions = require('utils/functions');
_ = require('lodash');
$ = require('jquery');
UserActions = require('./actions/UserActions');
UserStore = require('./stores/UserStore');
Select2 = require('select2');
Toastr = require('toastr');
Select = require('react-select'); But still the same =( |
this is output of ├─┬ [email protected] |
I've just created clean rails app, next installed react-reails and react-select and got this error again. You could try it by yourself https://gitlab.com/CostaRico/test-react-select/ |
Thanks for posting that example. Here's a related issue on react-select: JedWatson/react-select#606 Sounds like most cases is requiring React more than once. I think I see React being loaded twice in your app, too:
I think you could fix this problem by loading React only once:
Maybe you don't want to structure your app that way, but it would test if it's a dependency management problem! |
@rmosolgo hello, I've done what u told me, and it seems you are right, but. What do you think would be right way?
Thx a lot for your help! |
@CostaRico the browserify workflow takes care of the dependency management. Sprockets uses a different workflow and for that you have to use different versions of these modules separately. Rails assets https://rails-assets.org/ is one such place to import these libraries and make it work with Sprockets, however since you are using browserify I think it's best to use that. Also, please require var Select = require('react-select') and browserify will take care of all the dependencies etc. Same goes for react, autosize and other modules you are using. It makes sense to require them globally only if you are using it everywhere. Also, use this syntax: import React from 'react';
import Select from 'react-select'; Check some examples here: https://github.com/JedWatson/react-select/blob/master/examples/src/components/CustomComponents.js |
Hi there, I'm facing an issue when loading external react libraries (and react-select specifically). I've not implemented browserify workflow and use Sprockets. I've found on rails-assets.org the My
My
When loading my page, I get these errors in my inspector:
I first supposed that since react-select mention Any idea of what it can comme from. I probably miss something in the way of importing a react-library. What are you recommendation to load react libraries in my rails app using traditionnal asset pipeline? Thanks for your help, By the way, thanks for this awesome gem! |
I'm having the exact same issue as @maximedelpit, have you found any workarounds? 😞 |
i am facing same issue. Any help would be much appreciated. |
react-rails provides this library as var ReactDom = window.ReactDOM Please reopen or let me know if that doesn't work |
I having trouble with the Sprockets approach. I've tried including |
@reedlaw You can do it like so I guess, //= require react
console.log(React);
console.log(ReactDOM);
var ReactDom = window.ReactDOM
//= require react-select
//= require react_ujs |
Putting lines between the `//= require`s stops the loading of
`react-select` and `react_ujs`.
|
@reedlaw Ohh yeah, right sorry? Then, just load it via an external file. //= require react
//= require global-react-dom
//= require react-select
//= require react_ujs // global-react-dom.js
console.log(React);
console.log(ReactDOM);
var ReactDom = window.ReactDOM |
@gauravtiwari that works but somehow I still get an |
@reedlaw Because it's trying to find |
@gauravtiwari I followed @maximedelpit above. |
@reedlaw I suggest the easiest option is to download the Dist build and put it in Please note, you don't need to then explicitly declare that ReactDom variable because it will work with |
@gauravtiwari the Dist build seems to work. However I get a |
@reedlaw Use this for classnames, https://rails-assets.org/#/components/classnames (as gem) and dist build for autosize input, https://github.com/JedWatson/react-input-autosize |
@reedlaw that's why using asset pipeline nowadays is painful for JS. Take a look at this, https://github.com/gauravtiwari/rails-webpacker (Webpack and Yarn support is coming in Rails 5.1) |
@guaravTiwari finally it works. Thanks. I'll have to check out |
@reedlaw what specific versions of |
I've installed react-select with npm, next in components.js:
Next, when I use react-select component I see the error "Only a ReactOwner can have refs. You might be adding"
How to install react-select?
The text was updated successfully, but these errors were encountered: