You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
HOC that connects any toggle or checkbox component to a Formik boolean field.
Props injected automatically
Prop
Type
Description
value
boolean
Current boolean value from Formik state
error
string?
Validation error string for this field
touched
boolean?
Whether the field has been touched
onPress
fn
Toggles the field value and marks the field as touched
Field props
Prop
Type
Description
name
string
Formik field name (required)
Example
import{withBooleanField}from'react-native-formik-helper'import{Checkbox}from'./components/Checkbox'import{Switch}from'react-native'constAcceptTosField=withBooleanField<CheckboxProps>(Checkbox)constNotificationsToggle=withBooleanField<SwitchProps>(Switch)<Form ...><AcceptTosFieldname="acceptedTos"label="I agree to the terms and conditions"/><NotificationsTogglename="notificationsEnabled"label="Enable push notifications"/></Form>
Touched-gated error display
// In your Checkbox component:functionCheckbox({ value, onPress, error, touched }){return(<View><TouchableOpacityonPress={onPress}>{value ? <CheckIcon/> : <EmptyBox/>}</TouchableOpacity>{touched&&error ? <Textstyle={styles.error}>{error}</Text> : null}</View>)}