Skip to main content
Primer Checkout React Native SDK is currently in beta (v3.0.0-beta.1). The API is subject to change before the stable release.
The four card inputs each render one card field that is already wired to the card form: PrimerCardNumberInput, PrimerExpiryDateInput, PrimerCVVInput and PrimerCardholderNameInput. Arrange them yourself when the fixed layout of PrimerCardForm doesn’t fit. PrimerTextInput is the styled text input they are built on. Use it for other fields so they look the same. The card inputs must be inside PrimerCheckoutProvider and PrimerCardFormProvider. Without PrimerCardFormProvider they throw.

Usage

  • Render PrimerCardholderNameInput only when usePrimerCardForm().isCardholderNameVisible is true, as PrimerCardForm does.
  • PrimerCVVInput is labelled CVV by default. Pass descriptor.cvvLabel to follow the detected network, as PrimerCardForm does.
  • The card form must be active before it validates or pays. See PrimerCardForm.

Card input props

All four card inputs take the same props, exported as PrimerCardInputProps. The aliases PrimerCardNumberInputProps, PrimerExpiryDateInputProps, PrimerCVVInputProps and PrimerCardholderNameInputProps are the same type. The default label and placeholder follow the device language. See usePrimerLocalization. The card inputs set their value, change handler, error message and focus handlers themselves from usePrimerCardForm. To control a field yourself, build it with PrimerTextInput and the hook’s update functions, as in Your own field. Each card input forwards a ref of type PrimerTextInputRef: Each card input shows its field’s message from usePrimerCardForm().errors below the field, with the error border. See When errors show.

PrimerCardNumberInput

The co-badged selector is PrimerCardNetworkSelector. Don’t add another one next to this input.

PrimerExpiryDateInput

PrimerCVVInput

PrimerCardholderNameInput

PrimerTextInput

PrimerTextInput is a controlled text input with the label, border, focus and error styles of the card inputs. It doesn’t read the card form, so you can use it for any field. It also works outside PrimerCheckoutProvider, where it uses the default tokens for the device’s light or dark mode.

Props

The props type is exported as PrimerTextInputProps. PrimerTextInput forwards a ref of type PrimerTextInputRef with focus(), blur() and setCaret(start, end?), as described under Card input props.

States and accessibility

  • The border color follows the state. A disabled field uses the disabled color. Otherwise an error wins over focus, and focus wins over the resting color.
  • A field with an error is marked as invalid. Screen readers read the error together with the label when the field gets focus.
  • Screen readers announce a new error.

PrimerTextInputTheme

Pass a PrimerTextInputTheme to the theme prop of PrimerTextInput or of a card input to style that one input. Every key is optional. A key you leave out falls back to a design token of the active light or dark theme. CardInputTheme is an alias of the same type.
  • The label uses fontFamily when you set it, otherwise typography.bodySmall.fontFamily.
  • The text and label of a disabled field use colors.textDisabled.
To restyle every input and the rest of the UI at once, set tokens in the theme prop of PrimerCheckoutProvider. Use PrimerTextInputTheme only for changes to single inputs.

See also

PrimerCardForm

The four card inputs in a fixed layout.

usePrimerCardForm

Field values, update functions, validation and submit().

Card networks

The co-badged network selector and network icons.

PrimerThemeOverride

Design tokens for the whole checkout UI.