React 组件
2018-03-28 本文已影响5人
凌雲木
<div id="root1">
<!-- This element's contents will be replaced with your component. -->
</div>
<div id="root">
<!-- This element's contents will be replaced with your component. -->
</div>
//渲染元素
const element1 = <h1>React API</h1>;
ReactDOM.render(
element1,
document.getElementById('root1')
);
//渲染组件
function Welcome(props) {
return <h1>{props.name}</h1>;
};
const element = <Welcome name="Sa3ra" />;
ReactDOM.render(
element,
document.getElementById('root')
);
结果:
React API
Sa3ra
//渲染元素
const element1 = <h1>React API</h1>;
ReactDOM.render(
element1,
document.getElementById('root1')
);
//渲染组件间调用
function Welcome(props) {
return <h1>{props.name}</h1>;
};
function APP(){
return <Welcome name="Sa3raEEEE组件" />
};
//const element = <Welcome name="Sa3ra" />;
ReactDOM.render(
<APP/>,
document.getElementById('root')
);
结果:
React API
Sa3raEEEE组件