Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124


How to use React children prop in Typescript

How to use children prop in react typescript app

First you can create a interface to specify the props needed in the component. Then you can extends that interface from React.PropsWithChildren which contain children prop.

import React from 'react'

interface props extends React.PropsWithChildren {

function CustomComponent({children}:props) {
  return (
     <p>Inside Component</p>

export default CustomComponent

You can use the component like below in the application. The content under the CustomComponent will be rendered inside the div which is specified the children prop.

   <p>Inside Main App 1</p>
   <p>Inside Main App 2</p>