我不将formik的Field
与react-native一起使用
因为医生说<Field /> will default to an HTML <input /> element
我想使用useField
(https://stackoverflow.com/a/58650742/433570)
想知道useField
是否可以与react-native一起使用?
import React from "react";
import { useField, useFormikContext } from "formik";
import DatePicker from "react-datepicker";
export const DatePickerField = ({ ...props }) => {
const { setFieldValue } = useFormikContext();
const [field] = useField(props);
return (
<DatePicker
{...field}
{...props}
selected={(field.value && new Date(field.value)) || null}
onChange={val => {
setFieldValue(field.name, val);
}}
/>
);
};