I am creating a React component for my InertiaJS app that accepts children with a callback for passing the parent’s state to the current children.
To clarify, here’s a snippet from the Menu component of HeadlessUI.
As shown, the children are wrapped inside a callback with an active
prop. This prop allows us to style the button’s className
as the state changes.
Here’s a simplified version of a component where you can pass children with a callback or just normal children:
You can now use it like this:
Or you can pass a normal component as children without a callback:
Ref: Medium