All Projects ā†’ geolessel ā†’ React Phoenix

geolessel / React Phoenix

Licence: mit
Make rendering React.js components in Phoenix easy

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to React Phoenix

live dj
šŸ’æ Join or create video playlists to share a real-time experience with others! šŸŽ§
Stars: āœ­ 19 (-95.54%)
Mutual labels:  phoenix, phoenix-framework
king of tokyo
šŸ‘‘ King of Tokyo Multiplayer Board Game using Phoenix LiveView
Stars: āœ­ 25 (-94.13%)
Mutual labels:  phoenix, phoenix-framework
gringotts payment
Demo Phoenix app showing gringotts payment library integrations.
Stars: āœ­ 24 (-94.37%)
Mutual labels:  phoenix, phoenix-framework
Hammer
An Elixir rate-limiter with pluggable backends
Stars: āœ­ 366 (-14.08%)
Mutual labels:  phoenix, phoenix-framework
curious messenger
Companion repository for Phoenix LiveView Messenger app by Curiosum.dev. Part 1: https://curiosum.dev/blog/elixir-phoenix-liveview-messenger-part-1?utm_source=github&utm_medium=social, Part 2: https://curiosum.dev/blog/elixir-phoenix-liveview-messenger-part-2?utm_source=github&utm_medium=social, Part 3: https://curiosum.dev/blog/elixir-phoenix-lā€¦
Stars: āœ­ 30 (-92.96%)
Mutual labels:  phoenix, phoenix-framework
pokerex client
Elm client for PokerEx project
Stars: āœ­ 39 (-90.85%)
Mutual labels:  phoenix, phoenix-framework
poker ex
Texas Hold 'Em app written in Elixir with Phoenix and OTP
Stars: āœ­ 58 (-86.38%)
Mutual labels:  phoenix, phoenix-framework
Phoenix And Elm
Example application using Elixir, Phoenix and Elm
Stars: āœ­ 188 (-55.87%)
Mutual labels:  phoenix, phoenix-framework
pryin
PryIn is an Application Performance Monitoring platform for your Elixir/Phoenix application.
Stars: āœ­ 25 (-94.13%)
Mutual labels:  phoenix, phoenix-framework
elixir jobs
A job board to publish and find Elixir offers.
Stars: āœ­ 83 (-80.52%)
Mutual labels:  phoenix, phoenix-framework
Papercups
Open-source live customer chat
Stars: āœ­ 4,554 (+969.01%)
Mutual labels:  phoenix, phoenix-framework
phoenix bakery
Better compression for your Phoenix assets
Stars: āœ­ 25 (-94.13%)
Mutual labels:  phoenix, phoenix-framework
phoenix assets webpack
Asset Pipeline with Webpack on Phoenix
Stars: āœ­ 52 (-87.79%)
Mutual labels:  phoenix, phoenix-framework
zero-to-graphql-using-elixir
The purpose of this example is to provide details as to how one would go about using GraphQL with the Elixir Language.
Stars: āœ­ 20 (-95.31%)
Mutual labels:  phoenix, phoenix-framework
Realtime
Listen to your to PostgreSQL database in realtime via websockets. Built with Elixir.
Stars: āœ­ 4,278 (+904.23%)
Mutual labels:  phoenix, phoenix-framework
phoenix-liveview-15m.twitter
Based on the "real-time Twitter clone in 15 minutes with LiveView and Phoenix", from Chris McCord
Stars: āœ­ 40 (-90.61%)
Mutual labels:  phoenix, phoenix-framework
Phoenix Liveview Counter Tutorial
šŸ¤Æ beginners tutorial building a real time counter in Phoenix 1.5.5 + LiveView 0.14.7 āš”ļø
Stars: āœ­ 115 (-73%)
Mutual labels:  phoenix, phoenix-framework
Tune
A streamlined Spotify client and browser with a focus on performance and integrations.
Stars: āœ­ 166 (-61.03%)
Mutual labels:  phoenix, phoenix-framework
phoenix bootstrap form
Bootstrap 4 Forms for Phoenix/Elixir Applications
Stars: āœ­ 38 (-91.08%)
Mutual labels:  phoenix, phoenix-framework
game of life-elixir
An implementation of Conway's Game of Life in Elixir
Stars: āœ­ 22 (-94.84%)
Mutual labels:  phoenix, phoenix-framework

ReactPhoenix

Build Status Hex.pm

Functions to make rendering React.js components easy in Phoenix.

Combined with the javascript also included in this package, rendering React components in your Phoenix views is now much easier. Using the Phoenix default of Webpack, this package can make getting React into your application much faster than switching over to a different system.

Note regarding Phoenix versions <= 1.3

Phoenix versions 1.3 and earlier use Brunch by default instead of Webpack for asset compilation. The setup for apps using Brunch is different than apps using Webpack. If you'd like to read the old guide for 1.3/Brunch, you can read the Phoenix 1.3 README.

Installation in 4 (or 5) EASY STEPS!

This package is meant to be quick and painless to install into your Phoenix application. It is a thin wrapper to call the React render function from your Phoenix template and assumes you already have React in your project.

1. Declare the dependency

The package can be installed by adding react_phoenix to your list of dependencies in mix.exs:

def deps do
  [
    {:react_phoenix, "~> 1.2"}
  ]
end

After adding to your mix file, run:

mix deps.get

2. Add the javascript dependency to package.json

In order to correctly render a React component in your view templates, a provided javascript file must be included in your assets/package.json file in the dependencies section. It might look like this:

{
  ...
  "dependencies": {
    "phoenix": "file:../deps/phoenix",
    "phoenix_html": "file:../deps/phoenix_html",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-phoenix": "file:../deps/react_phoenix" <-- ADD THIS!
  },
  ...
}

Then run (from your assets directory)

npm install

or

yarn

yarn users

If you face the following error using yarn:

Error: "You may need an appropriate loader to handle this file type"

You may need to add the below to your assets/webpack.config.js file.

{ test: /\.jsx$/, use: { loader: 'babel-loader' } }

npm users

npm unfortunately needs an extra bit of configuration to make it happy. Add the following block to your assets/webpack.config.js file. If you use yarn to manage your dependencies, this extra bit of configuration should not be necessary.

module.exports = (env, options) => ({
  ...
  // ADD THIS BLOCK Ė…Ė…Ė…
  resolve: {
    alias: {
      react: path.resolve(__dirname, './node_modules/react'),
      'react-dom': path.resolve(__dirname, './node_modules/react-dom')
    }
  }
  // ADD THIS BLOCK ^^^
  ...
});

3. Make sure React and Babel presets are installed

Since we want React and would like to write JSX in our app, we need to make sure we get the packages brunch needs in order to compile our files.

# using npm
npm install react react-dom --save
npm install @babel/preset-env @babel/preset-react --save-dev

or

# using yarn
yarn add react react-dom
yarn add --dev @babel/preset-env @babel/preset-react

We also need to activate those presets from the assets/.babelrc file:

// Configure your plugins
{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react" // <-- ADD THIS!
  ]
}

4. Import and initialize the javascript helper

In your main application javascript file (usually assets/js/app.js), add the following line:

import "react-phoenix"

5. (optional) Import the module into your views for less typing

If you'd like to just call react_component(...) in your views instead of the full ReactPhoenix.ClientSide.react_component(...), you can import ReactPhoenix.ClientSide into your lib/APPNAME_web.ex views section. It might look like this:

def view do
  quote do
    use Phoenix.View,
      root: "web/templates",
      namespace: MyPhoenixApp

    import Phoenix.Controller, only: [get_flash: 1, get_flash: 2, view_module: 1]

    use Phoenix.HTML

    import MyPhoenixApp.ErrorHelpers
    import MyPhoenixApp.Gettext
    alias MyPhoenixApp.Router.Helpers, as: Routes

    import ReactPhoenix.ClientSide # <-- ADD THIS!
  end
end

Usage

Once installed, you can use react_component in your views by:

  1. Making sure that the component you'd like rendered is in the global namespace. You can do that in app.js like this (for example):

    import MyComponent from "./components/my_component"
    window.Components = {
      MyComponent
    }
    
  2. In your view template, you can then render it like this:

    # with no props
    <%= ReactPhoenix.ClientSide.react_component("Components.MyComponent") %>
    
    # with props
    <%= ReactPhoenix.ClientSide.react_component("Components.MyComponent", %{language: "elixir", awesome: true}) %>
    
    # with props and a target html element id option
    <span id="my-react-span"><%= @react_html %></span>
    <%= ReactPhoenix.ClientSide.react_component("Components.Characters", %{people: people}, target_id: "my-react-span") %>
    

    This will render a special div element in your html output that will then be recognized by the javascript helper as a div that should be turned into a React component. It will then render the named component in that div (or a different element specified by ID via the target_id option).

What about server-side rendering?

I couldn't quite get this working with Brunch, but I hope to have time to look at it again with Webpack.

Documentation and other stuff

This package is heavily inspired by the react-rails project.

For more detailed documentation, check out the hex docs at https://hexdocs.pm/react_phoenix

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].