Skip to content

Commit

Permalink
Merge branch 'master' of github.com:UseHover/preact-rails
Browse files Browse the repository at this point in the history
  • Loading branch information
ishuah committed Jul 10, 2019
2 parents 554b27a + e5f7a9b commit dc40a12
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,41 @@
# preact-rails
Preact integration for Ruby on Rails.

Under active development.
## Getting started

1. Add `webpacker` and `preact-rails` to your Gemfile
```
gem 'webpacker'
gem 'preact-rails'
```
2. Install the gems by running `bundle install`
3. Install the Preact UJS driver by running `yarn add preact_ujs` or `npm i preact_ujs`
4. Include your Preact components in your application.js
Update `app/javascript/packs/application.js`, add the following lines:
```
var componentRequireContext = require.context("components", true);
var PreactRailsUJS = require("preact_ujs");
PreactRailsUJS.useContext(componentRequireContext)
```
5. Create the directory `app/javascript/components`. That's where your Preact components will reside.
6. Create your first Preact component - create the file `app/javascript/components/Button.js` and add the following lines:
```
import { h, Component } from "preact"
class Button extends Component {
render (props, state) {
return (
<button className="button" type={props.type}>{props.label}</button>
);
}
}
export default Button
```
7. Link the javascript Pack in Rails, add `<%= javascript_pack_tag 'application' %>` to `app/views/layouts/application.html.erb`
8. Render your Preact component in a view
```
<%= preact_component('Button', { type: 'submit', label: 'Get started!'}) %>
```

12 changes: 12 additions & 0 deletions preact_ujs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Preact UJS

UJS driver for [preact-rails](https://github.com/UseHover/preact-rails).

## Install
```
npm i preact_ujs
```
or
```
yarn add preact_ujs
```

0 comments on commit dc40a12

Please sign in to comment.