Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

noderaider/react-dom-inject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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. --><divid="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
importReactfrom'react'importReactDOMInjectfrom'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. */exportconstMyReactElement=props=>{const{ title, color, defaultVisibility, children, description}=propsconststyle={ color,display:defaultVisibility ?'block' :'none'}return(<divstyle={style}><h1>{title}</h1><div>{children}</div></div>)}exportconstMyReactElementDOM=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]}])

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp