如何渲染组件的JSX子元素

时间:2016-09-16 03:54:23

标签: reactjs

我有一个代码来运行这样的应用程序:

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的范围?

1 个答案:

答案 0 :(得分:3)

子组件通过children prop传递给组件:

const AComponent = (props) => (
  <div>
      {props.children}
  </div>
);