jsファイルを作成し、反応したコンポーネントのレンダリングに役立つデフォルト関数をエクスポートします。同様
この
import React from 'react';
import ReactDOM from 'react-dom';
export default function(component, container , props = {}, callback){
React.createElement(component , props);
ReactDOM.render(component, container, callback);
}
あなたのコンポーネントは、この
import React,{PropTypes} from 'react';
class MySampleComponent extends React.Component{
static propTypes ={
hide : PropTypes.bool
}
static defaultProps= {
hide : false
}
render(){
return(
<div style={display : this.props.hide : 'none' : 'block'}> </div>
);
}
}
インポートのようにあなたがindex.htmlの中に追加するJSファイルにコンポーネントをレンダリングするために上記の機能を見ていきます
import render from './pathto/RenderHelper'
import MyComponent from './MyComponent'
class IndexPage {
constructor(){
this.renderUI();
}
renderUI(){
var container = document.getElementById('react-component');
render(MyComponent, container, {hide : false});
}
}
webpack.config.jsエントリにpage.index.jsファイルを追加する必要があるので、webpack caこれをコンパイルしてください。
entry: { page.index : 'location/to/page.index.js' }
希望します。
jqueryの '$ .hide()'と '$ .show()'は役に立ちませんか? – flocks
悲しいことに、それはうまくいきません。 $( "#react-component")。hide()は動作しません。 –
@VittVolt親divにstyle = {{display: 'none'}}を使ってみましたか? – Upasana