home ~ socials ~ projects ~ rss

Pass And Amend Element Props With A React Function

August 2021

This is with a spread and destructuring

function Box({className, ...rest}) {
    return <div className={`box ${className}`} {...rest} />
}
const element = (
    <Box className="blue" style={{fontStyle: 'italic'}}>
        This is the box
    </Box>
)

results in:

<div class="box blue" style="italic">
    This is the box
</div>
end of line
Share link:
https://www.alanwsmith.com/en/20/eo/kf/h7/?pass-and-amend-element-props-with-a-react-function