React-provider
HTML上の要素をReact.jsのコンポーネントに置換します。
Browserify + Babelifyの環境で動作確認済み。
loose-modeを用いることでIE8でも動作可能です。
主要な機能
- Component provider
- this.props.children
- data-props
1.Component provider
var elementMap = selector: <Component /> selector2: <Component />... ;
selector(string)で指定した要素にコンポーネントが展開されます。
指定されていたattributesはpropsに引き継がれます。
IE8は未定義タグに対応していないため、wrapTagNameにdivやspanを渡して対応して下さい。
使用例
component.jsx
;Component { return <div className=thispropsclassName> thispropschildren </div> ; }
app.js
var Component = ;var provider = ; ;
index.html (実行前)
wrappertext innertext
index.html (実行後)
wrappertext innertext
2. this.props.children
変換対象要素の子要素がReactElementとして格納されます。
jsx内に{this.props.children}
と記述することで展開できます。
3. data-props属性
__data-props__を指定した要素はthis.props内に文字列として格納されます。
__data-props-html__を指定した要素はthis.props.html内にReactElementとして格納されます。
component.jsx
;Component { return <section> thispropshtmlreactelement thispropstextelement </section> ; }
index.html (実行前)
textnodeが格納されます htmlが格納されます
index.html (実行後)
htmlが格納されます textnodeが格納されます