A component whose injected props are optional.
import { withDefaultProps } from '@pacote/react-with-props'
type ComponentProps = { name: string; value: string }
const NameValue = (props: ComponentProps) => (
<div>{props.name}: {props.value}</div>
)
const Example = withDefaultProps({ name: 'Example' }, NameValue)
render(<Example value="with props" />)
// => <div>Example: with props</div>
const PasswordInput = withDefaultProps(
{ type: 'password', placeholder: 'Password' },
'input',
)
render(<PasswordInput name="secret" placeholder="API Key" />)
// => <input type="password" name="secret" placeholder="API Key" />
Creates a component with default props that callers may override.