使用过vue的小伙伴都知道vue中有个slot,也就是插槽,作用就是占位,那么再react中可以使用children来替代
父组件

render(){
    return( 
        <div>
            <Grid>
                我将被传递到Grid组件中
            </Grid>
        </div>
    )
}

子组件

export default class Grid extends React.Component {
    render() {
      return (
        <div>{this.props.children}</div>
      )
    }
}

这样就能够够实现slot的功能了。

相关文章:

  • 2023-02-03
  • 2021-06-11
  • 2022-12-23
  • 2022-01-02
  • 2021-09-06
  • 2022-12-23
猜你喜欢
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案