Home > Enterprise >  Access children in function component without the props parameter
Access children in function component without the props parameter

Time:03-30

i've created a class that looks like this:

const Button = ({href, className, rippleColor, type}) => {
... 
}

i'm using the component like this:

<Button rippleColor={'#ff0000'} type={'primary'} className={'my-4'}>Test</Button>

now i want to get access to the props.children of the component without switching ({href, className, rippleColor, type}) to (props)

is there a way to do this?

CodePudding user response:

Yes, simply add children to your destructuring,

const Button = ({children, href, className, rippleColor, type}) => {
... 
}
  • Related