A component whose props exclude the injected keys.
import { withProps } from '@pacote/react-with-props'
type ComponentProps = { name: string; value: string }
const NameValue = (props: ComponentProps) => (
<div>{props.name}: {props.value}</div>
)
const ExampleValue = withProps({ name: 'Example' }, NameValue)
render(<ExampleValue value="with props" />)
// => <div>Example: with props</div>
const FieldValue = withProps(
({ field = '' }) => ({ name: `[${field}]` }),
NameValue,
)
render(<FieldValue field="Example" value="with props" />)
// => <div>[Example]: with props</div>
const PasswordInput = withProps({ type: 'password' }, 'input')
render(<PasswordInput name="secret" />)
// => <input type="password" name="secret" />
Creates a component that injects preset props into another component.
The injected props may be an object or a function of the props supplied by the caller. Caller props are spread first, so injected values take precedence.