Integrate React Payment Inputs with third-party UI libraries
masterYou can integrate react-payment-inputs into any UI library (like Bootstrap or Fannypack) by using the usePaymentInputs hook to extract props and metadata.
To ensure proper integration:
- Spread the
get...Props()onto your library's input component. - Pass the
reffrom the props to the library'sinputRefprop if available. - Use
meta.erroredInputsandmeta.touchedInputsto drive the library's error/invalid states.
// Example: Integrating with a generic InputField
import { usePaymentInputs } from 'react-payment-inputs';
export default function MyCustomForm() {
const { meta, getCardNumberProps, getExpiryDateProps, getCVCProps } = usePaymentInputs();
const { erroredInputs, touchedInputs } = meta;
return (
<InputField
{...getCardNumberProps()}
inputRef={getCardNumberProps().ref}
state={erroredInputs.cardNumber && touchedInputs.cardNumber ? 'danger' : undefined}
validationText={touchedInputs.cardNumber && erroredInputs.cardNumber}
/>
// ... repeat for other fields
);
}