GithubHelp home page GithubHelp logo

noderaider / react-dom-inject Goto Github PK

View Code? Open in Web Editor NEW
18.0 4.0 4.0 55 KB

Binds an HTML element by selector to a ReactElement and renders to a DOM tree (with redux injection)

Home Page: https://noderaider.github.io/react-dom-inject/

License: MIT License

JavaScript 100.00%
reactelement dom-tree legacy-application redux-injection selector html-element

react-dom-inject's Introduction

react-dom-inject

Binds an HTML element by selector to a ReactElement and renders to a DOM tree (with redux injection)

Install

npm i -S react-dom-inject

Usage

This package was written to ease transition of legacy applications from older systems component by component. It can be used to rewrite legacy components as react components, and then inject them into placeholder elements in the legacy application without requiring them to be in the same tree as the new react application.

index.html
<!-- ... -->

<!-- All data properties will be camelCased and injected into the components props object. Any innerHTML will be injected into the children element of your react component. -->
<div id="my-element" data-title="My Element!" data-color="#ff0000" data-default-visibility="false">
  <span>Some inner HTML to be injected here</span>
</div>

<!-- ... -->
MyReactElement.jsx
import React from 'react'
import ReactDOMInject from 'react-dom-inject'

/**
 * ReactElement to be injected.
 * This could be a regular class element but for this example I'm using an inline function style element.
 */
export const MyReactElement = props => {
  const { title, color, defaultVisibility, children, description } = props
  const style = { color
                , display: defaultVisibility ? 'block' : 'none'
                }
  return (
    <div style={style}>
      <h1>{title}</h1>
      <div>
        {children}
      </div>
    </div>
  )
}

export const MyReactElementDOM = ReactDOMInject(MyReactElement)

render.js

import { MyReactElementDOM } from './MyReactElement'

...

MyReactElementDOM.render('#my-element'[, { description: 'This is a way to pass properties to the element at render time.'[, state: reduxState ] } ])

react-dom-inject's People

Contributors

cchamberlain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-dom-inject's Issues

`children` does not work

props.children does not work, so currently the README example is a bit misleading by using {children}.

Great lib, nevertheless. data-* properties already provide a seamless way for ServerSideTemplatingEngine--React interaction.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.