父子组件

2020-08-16  本文已影响0人  一土二月鸟

创建父子组件的两种方式

import React from 'react';
import ReactDOM from 'react-dom';

const Parent = (props) => {
  return <>
    i am parent
    <ChildSon />
    <ChildDaughter />
  </>;
}

const ChildSon = () => {
  return <p>i am son</p>;
}

const ChildDaughter = () => {
  return <p>i am daughter</p>;
}

const Index = () => <>
  <Parent></Parent>
</>

ReactDOM.render(<Index />, document.getElementById('root'));
import React from 'react';
import ReactDOM from 'react-dom';

const Parent = (props) => {
  return <>
    i am parent
    {props.children}
  </>;
}

const ChildSon = () => {
  return <p>i am son</p>;
}

const ChildDaughter = () => {
  return <p>i am daughter</p>;
}

const Index = () => <>
  <Parent>
    <ChildSon />
    <ChildDaughter />
  </Parent>
</>

ReactDOM.render(<Index />, document.getElementById('root'));
上一篇下一篇

猜你喜欢

热点阅读