danott / react-rails-form-helpers

Components for composing forms targeted at Rails
MIT License
81 stars 18 forks source link

How do I import the helpers into my jsx file? #9

Closed javogel closed 6 years ago

javogel commented 6 years ago

Sorry for my basic question, but I tried several ways and was not able use the components. What would be the correct way to import them? After having the package installed in my node_modules.

danott commented 6 years ago

Whoops! Looks like my examples in the README glazed over this absolutely necessary part of using a library.

Assuming you're in an environment where you can require the npm install'd files, Here's a rough example that should work everywhere.

var ReactRailsFormHelpers = require("react-rails-form-helpers")

<ReactRailsFormHelpers.FormFor />

// You could assign the individual components to a local variable. 
var FormFor = ReactRailsFormHelpers.FormFor
<FormFor />

If you're in an environment where you've got ES2015 transpiling at your disposal, I favor the import syntax for modules.

import {
  FormFor,
} from "react-rails-form-helpers"

Hope that helps!