TypeScript React FComponent with children

    0

    2

    The code above defines a interface named NameComponentProps and exports a function that takes two arguments. The first argument is an instance of JSX.Element and the second argument is an instance of PropsWithChildren .

    The NameComponent function takes an instance of FC and returns an instance of PropsWithChildren . The FC class defines a mutable interface that can be used to bind properties to elements. The PropsWithChildren class defines a immutable interface that can be used to bind child elements to properties.

    Library: react

    Shortcut: tsrafchd

    import React, { FC, PropsWithChildren } from 'react';
    
    interface NameComponentProps {
      children: JSX.Element;
    }
    
    export const NameComponent: FC<PropsWithChildren<NameComponentProps>> = ({
      children,
    }) => {
      return <div>{children}</div>;
    };
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.