我有一个代码来运行这样的应用程序:
import React from 'react'
import { render } from 'react-dom'
import AComponent from './components/AComponent'
render(
<AComponent>
<span id="needShow">HTML inner Component Tag</span>
</AComponent>,
document.getElementById('root')
)
这是组件代码:
import React from 'react'
const AComponent = () => (
<div>
<span> Hello of AComponent</span>
</div>
)
export default AComponent
如何显示ID为needShow
的范围?
答案 0 :(得分:3)
子组件通过children
prop传递给组件:
const AComponent = (props) => (
<div>
{props.children}
</div>
);