TypeScript and React - children type?

前端 未结 14 1259
借酒劲吻你
借酒劲吻你 2020-12-12 18:56

I have a very simple functional component as follows:

import * as React from \'react\';

export interface AuxProps  { 
    children: React.ReactNode
 }


con         


        
14条回答
  •  無奈伤痛
    2020-12-12 19:02

    As a type that contains children, I'm using:

    type ChildrenContainer = Pick
    

    This children container type is generic enough to support all the different cases and also aligned with the ReactJS API.

    So, for your example it would be something like:

    const layout = ({ children }: ChildrenContainer) => (
        
            
    Toolbar, SideDrawer, Backdrop
    {children}
    )

提交回复
热议问题