All Projects → janlelis → render_react

janlelis / render_react

Licence: MIT license
Pre-render and mount React components from Ruby

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to render react

Laravel Blade X
Use custom HTML components in your Blade views
Stars: ✭ 538 (+3742.86%)
Mutual labels:  components, view
echo-template
golang template for echo framework!
Stars: ✭ 39 (+178.57%)
Mutual labels:  view, render
Val
VirtualDOM abstraction layer - give yourself better integration and full control over the DOM with any virtual DOM library that uses a Hyperscript-like API such as React and Preact.
Stars: ✭ 181 (+1192.86%)
Mutual labels:  components, preact
Gin Template
golang template for gin framework!
Stars: ✭ 106 (+657.14%)
Mutual labels:  view, render
Preact
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
Stars: ✭ 30,527 (+217950%)
Mutual labels:  components, preact
Redux React Starter
DEPRECATED use the new https://github.com/didierfranc/react-webpack-4
Stars: ✭ 137 (+878.57%)
Mutual labels:  components, preact
blade
🏃 A library for using Laravel Blade templates in WordPlate.
Stars: ✭ 28 (+100%)
Mutual labels:  view, render
react-native-element-textinput
A react-native TextInput, TagsInput and AutoComplete component easy to customize for both iOS and Android.
Stars: ✭ 28 (+100%)
Mutual labels:  components
LockerScreen
Android lock screen,slide to unlock ! 安卓锁屏,上滑解锁,效果酷炫,值得拥有!
Stars: ✭ 81 (+478.57%)
Mutual labels:  view
DNZ.MvcComponents
A set of useful UI-Components (HtmlHelper) for ASP.NET Core MVC based-on Popular JavaScript Plugins (Experimental project).
Stars: ✭ 25 (+78.57%)
Mutual labels:  components
PlayView
一个仿有道词典播放音乐的控件
Stars: ✭ 13 (-7.14%)
Mutual labels:  view
dockview
Zero dependency layout manager and builder with ReactJS support
Stars: ✭ 45 (+221.43%)
Mutual labels:  components
nativeweb
🤳 Tiny library for simple web components. [1kB]
Stars: ✭ 93 (+564.29%)
Mutual labels:  components
Portfolio
Expo + Next.js Portfolio
Stars: ✭ 56 (+300%)
Mutual labels:  preact
windows-network-drive
Do network drive stuff on Microsoft Window in node
Stars: ✭ 18 (+28.57%)
Mutual labels:  mount
Decompose
Kotlin Multiplatform lifecycle-aware business logic components (aka BLoCs) with routing functionality and pluggable UI (Jetpack Compose, SwiftUI, JS React, etc.), inspired by Badoos RIBs fork of the Uber RIBs framework
Stars: ✭ 799 (+5607.14%)
Mutual labels:  components
LuckPan
幸运转盘,可以控制选中指定的奖项。
Stars: ✭ 15 (+7.14%)
Mutual labels:  view
preact-weui
Weui for preact.
Stars: ✭ 44 (+214.29%)
Mutual labels:  preact
CheckableTextView
A simple and flexible Checked TextView or Checkable TextView
Stars: ✭ 108 (+671.43%)
Mutual labels:  view
tesserae
Components for building h5-based single-page-applications using C#
Stars: ✭ 23 (+64.29%)
Mutual labels:  components

RenderReact [version] [ci]

A lo-fi way to render client- and server-side React components from Ruby:

class ExampleComponent extends React.Component {
  render() {
    return <marquee>Hello Ruby { this.props.example }</marquee>
  }
}
RenderReact.on_client_and_server("ExampleComponent", { example: "!" })
# =>
<div id="RenderReact-caac405e-1714-495e-aeb4-77b42be42291">
  <marquee data-reactroot="" data-reactid="1" data-react-checksum="441921122">
    <!-- react-text: 2 -->Hello Ruby <!-- /react-text --><!-- react-text: 3 -->!<!-- /react-text -->
  </marquee>
</div>
<script>
  RenderReact.ReactDOM.render(
    RenderReact.React.createElement(
      RenderReact.components.ExampleComponent, {"example":"!"}
    ),
    document.getElementById('RenderReact-caac405e-1714-495e-aeb4-77b42be42291')
  )
</script>

It is bring your own tooling: React is not included, nor any ES6 transpilers or module bundlers. It expects you to prepare the JavaScript bundle file in a specific format, which must contain React and all of your components.

If you are looking for higher-level alternatives, checkout react_on_rails or react-rails.

Setup

Add to your Gemfile:

gem 'render_react'

JavaScript Source Preparation

RenderReact expects the JavaScript bundle to include a global variable called RenderReact with the following contents:

{
  React: [variable which contains React],
  ReactDOM: [variable which contains ReactDOM],
  ReactDOMServer: [variable which contains ReactDOMServer],
  components: {
    ComponentIdentifier1: [variable which contains the component 1],
    ComponentIdentifier2: [variable which contains the component 2],
    ...
  }
}

You can have two different javascript bundle files - one for server rendering, and one for client-rendering.

  • The client bundle has to be included into your application by a method of your choice. You may skip passing in ReactDOMServer for the client bundle
  • The server bundle has to be passed to RenderReact (see Usage section). You may skip passing in ReactDOM for the server bundle

Example (With ES6 Modules)

import React from 'react'
import ReactDOM from 'react-dom'
import ReactDOMServer from 'react-dom/server'

import ExampleComponent from './components/example_component'

export default {
  React: React,
  ReactDOM: ReactDOM,
  ReactDOMServer: ReactDOMServer,
  components: {
    ExampleComponent: ExampleComponent
  }
}

Gets imported as RenderReact

Example (With Browser Globals)

window.RenderReact = {
  React: React,
  ReactDOM: ReactDOM,
  ReactDOMServer: ReactDOMServer,
  components: {
    ExampleComponent: ExampleComponent
  }
}

Usage

Create a RenderReact context by passing your server-side JavaScript bundle:

RenderReact.create_context! File.read('path/to/your/server-bundle.js'), mode: :client_and_server

You can use it without a server-side bundle by not passing any file source.

The optional mode: keyword argument can have one of the following values

  • :client_and_server (default) - component will be rendered server-side and mounted in the client
  • :client - component will be mounted in the client
  • :server - component will be render statically

You can then render a component with

RenderReact.("ExampleComponent", { example: "prop" })

It is possible to overwrite the context-rendering-mode by using specfic render methods:

RenderReact.on_client_and_server("ExampleComponent") # server- and client-side
RenderReact.on_client("ExampleComponent") # only client-side
RenderReact.on_server("ExampleComponent") # only static

MIT License

Copyright (C) 2017 Jan Lelis https://janlelis.com. Released under the MIT license.

React is BSD licensed.

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].