Skip to content

Commit

Permalink
Add pushEvent to docs/readme
Browse files Browse the repository at this point in the history
  • Loading branch information
fidr committed Sep 19, 2019
1 parent 8f1b2af commit 8e2dbdd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ def render(assigns) do
end
```

### Events

To push events back to the liveview the `pushEvent` function from Phoenix LiveView is passed as a prop
the the component.

* pushEvent(event, payload) - method to push an event from the client to the LiveView server

```javascript
const { pushEvent } = this.props;
pushEvent("button_click");
pushEvent("myevent", {"var": "value"});
```

## How to add react to your phoenix app

In your assets dir:
Expand All @@ -69,7 +82,7 @@ Create an `assets/.babelrc` file:
}
```

For NPM users, you might need the add the folloing to your `assets/webpack.config.js` file:
For NPM users, you might need the add the following to your `assets/webpack.config.js` file:
```
module.exports = (env, options) => ({
// add:
Expand Down
13 changes: 13 additions & 0 deletions lib/phoenix_live_react.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ defmodule PhoenixLiveReact do
<%= PhoenixLiveReact.live_react_component("Components.MyComponent", %{name: "Bob"}) %>
```
## Events
To push events back to the liveview the `pushEvent` function from Phoenix LiveView is passed as a prop
the the component.
* pushEvent(event, payload) - method to push an event from the client to the LiveView server
```
const { pushEvent } = this.props;
pushEvent("button_click");
pushEvent("myevent", {"var": "value"});
```
## Parameters
- name: String with the module name of the component
Expand Down

0 comments on commit 8e2dbdd

Please sign in to comment.