š Instant pain reliever for using Formik with Office UI Fabric React š
To reduce the boilerplate code needed to get Fabrics input components work seamlessly with Formiks field props and validation errors.
yarn add formik-office-ui-fabric-react
# or
npm install --save formik-office-ui-fabric-react
FooComponent
with FormikFooComponent
or use the mapFieldToFooComponent
, i.eimport { Formik, Form, Field } from 'formik'
import { DatePicker } from 'office-ui-fabric-react'
import { FormikDatePicker, mapFieldToDatePicker } from 'formik-office-ui-fabric-react'
const OldAndUgly = () => (
<Formik initialValues={{ date: new Date() }}>
<Form>
<Field
name="date"
render={fieldProps => (
<DatePicker
value={/* wrapper code for fieldProps.value */}
onSelectDate={/* wrapper code for fieldProps.onChange */}
{/* and more ugly wrapper code trying to get name, onBlur, etc. working */}
/>
)}
/>
</Form>
</Formik>
)
// using the component
const NewAndPretty = () => (
<Formik initialValues={{ date: new Date() }}>
<Form>
<Field name="date" component={FormikDatePicker} />
</Form>
</Formik>
)
// or using the map function
const NewAndAlsoPretty = () => (
<Formik initialValues={{ date: new Date() }}>
<Form>
<Field name="date" render={fieldProps => (
<DatePicker {...mapFieldToDatePicker(fieldProps)} />
)} />
</Form>
</Formik>
)
git clone https://github.com/kmees/formik-office-ui-fabric-react
cd formik-office-ui-fabric-react && yarn install
yarn start
yarn test