• Stars
    star
    111
  • Rank 314,510 (Top 7 %)
  • Language
    Elixir
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

React SSR Framework for Elixir

ReactRender

Build Status Hex.pm License: MIT Coverage Status

Renders React as HTML

Documentation

The docs can be found at https://hexdocs.pm/react_render.

Installation

def deps do
  [
    {:react_render, "~> 3.0.0"}
  ]
end

Getting Started with Phoenix

  • Add react_render to your dependencies in package.json

    "react_render": "file:../deps/react_render"
  • Run npm install

    npm install
  • Create a file named render_server.js in your assets folder and add the following

    require('@babel/polyfill')
    require('@babel/register')({cwd: __dirname})
    
    module.exports = require('react_render/priv/server')

    Note: You must move any @babel used for server-side rendering from devDependencies to dependencies in your package.json file. This is required when installing dependencies required for production as these packages.

  • Add ReactRender to your Supervisor as a child. We're using the absolute path to ensure we are specifying the correct working directory that contains the render_server.js file we created earlier.

      render_service_path = "#{File.cwd!}/assets"
      pool_size = 4
    
      supervisor(ReactRender, [[render_service_path: render_service_path, pool_size: 4]])
  • Create a react component like:

    import React, {Component, createElement} from 'react'
    
    class HelloWorld extends Component {
      render() {
        const {name} = this.props
    
        return <div>Hello {name}</div>
      }
    }
    
    export default HelloWorld
  • Call ReactRender.render/2 inside the action of your controller

    def index(conn, _params) do
      component_path = "#{File.cwd!}/assets/js/HelloWorld.js"
      props = %{name: "Revelry"}
    
      { :safe, helloWorld } = ReactRender.render(component_path, props)
    
      render(conn, "index.html", helloWorldComponent: helloWorld)
    end

    component_path can either be an absolute path or one relative to the render service. The stipulation is that components must be in the same path or a sub directory of the render service. This is so that the babel compiler will be able to compile it. The service will make sure that any changes you make are picked up. It does this by removing the component_path from node's require cache. If do not want this to happen, make sure to add NODE_ENV to your environment variables with the value production.

  • Render the component in the template

    <%= raw @helloWorldComponent %>
  • To hydrate server-created components in the client, add the following to your app.js

    import {hydrateClient} from 'react_render/priv/client'
    import HelloWorld from './HelloWorld.js'
    
    function getComponentFromStringName(stringName) {
      // Map string component names to your react components here
      if (stringName === 'HelloWorld') {
        return HelloWorld
      }
    
      return null
    }
    
    hydrateClient(getComponentFromStringName)
  • Update assets/webpack.config to include under the resolve section so that module resolution is handled properly:

    resolve: {
      symlinks: false
    }
    

More Repositories

1

elixir-nodejs

An Elixir API for calling Node.js functions
Elixir
169
star
2

ecto_soft_delete

Soft Deletion for Ecto
Elixir
110
star
3

text_chunker_ex

A library for semantically coherent text chunking
Elixir
65
star
4

harmonium

An opinionated React component framework for teams that move fast.
JavaScript
34
star
5

revelry_phoenix_app_template

App Template for Revelry Phoenix
Elixir
32
star
6

ecto_explain

Elixir
25
star
7

elixir-stellar-client

Elixir Client for Stellar
Elixir
21
star
8

sassy-npm-importer

Import SASS from npm via a customizable prefix.
JavaScript
18
star
9

adminable

Allows creating admin interfaces through implementing the `Adminable` behaviour
Elixir
15
star
10

hubkit

Hubkit provides methods for querying the github API at a higher level than making individual API calls. Think of it like an ORM for the github API.
Ruby
15
star
11

slax

Elixir Slack slash command handler
Elixir
13
star
12

ecto_filters

Elixir
12
star
13

liveview_web3

Elixir
10
star
14

phoenix_harmonium

Phoenix Framework view helpers for Harmonium-style components (https://harmonium.revelry.co)
Elixir
10
star
15

react-uniqueid

Provider component and connect function for generating unique identifiers in React.
JavaScript
8
star
16

storybot-ai

AI Generated User Stories from your CLI
JavaScript
6
star
17

aws_parameter_store_config_provider

Elixir
5
star
18

ecto_sort

Elixir
5
star
19

transmit

Plug for handling the creation of presigned urls for direct client-side uploading
Elixir
4
star
20

zoom-archive-scraper

Some example elixir code for scraping Zoom's Recording Management section for old recordings
Elixir
4
star
21

exdr

Elixir
4
star
22

bn-mobile-react

BigNeon React Native Repo
JavaScript
2
star
23

velocity_calculator

Elixir
2
star
24

tenk

An unofficial Ruby API wrapper for working with the 10k Plans (http://www.10000ft.com/).
Ruby
2
star
25

moondog-engine

An opinionated bootstrapper for Goodâ„¢ Kubernetes clusters.
Shell
2
star
26

metairie

Set of modules for monitoring Elixir/Phoenix apps and sending them to a statsD compatible client
Elixir
2
star
27

Harmonium-RN

Reactive Native Harmonium Styles
JavaScript
1
star
28

react-native-duration-picker

A duration picker component for React Native
JavaScript
1
star
29

revelry-koans

Elixir
1
star
30

journal

Versioned key/value store with multiple backend support
Elixir
1
star
31

ex_selfie

Provides a single way to access both a struct's fields and its associated module's functions.
Elixir
1
star
32

slush-revelry

A generator for Revelry Node.js apps that use React, Redux, and more.
JavaScript
1
star
33

tracing

Contact Tracing Prototype
1
star
34

helm-charts

Our public helm charts
Smarty
1
star
35

review_bot_operator

Elixir
1
star