reactjs / react-rails

Integrate React.js with Rails views and controllers, the asset pipeline, or webpacker.
Apache License 2.0
6.75k stars 759 forks source link

How do you require react-modal in your app? #510

Closed adoseofjess closed 7 years ago

adoseofjess commented 8 years ago

Help us help you! Please choose one:


This is not an issue, just a question. How would you go about using this https://github.com/reactjs/react-modal in your react-rails app?

rmosolgo commented 8 years ago

I'm using Sprockets, here's how I'd do it:

scottbarrow commented 8 years ago

@rmosolgo would you suggest a way this could be done with a non-compiled library, e.g https://github.com/andreypopp/autobind-decorator

rmosolgo commented 8 years ago

People usually "compile" their compiles-to-JS languages before pushing to NPM, right? So npmcdn might have the compiled version: https://npmcdn.com/autobind-decorator@1.3.3

The only problem is that it looks like that is made for a NodeJS-like environment, I see that it assumes an object named exports exists.

You could remove those lines to prepare the file for the browser:

// Remove these:
exports['default'] = autobind;
//...
module.exports = exports['default'];

Or, since this package is meant to be used with Babel, maybe babel will take care of it?

rmosolgo commented 7 years ago

React-rails 2.0.0 will support https://github.com/rails/webpacker which brings nodejs build processes to Rails!