Skip to content

Commit bfe0742

Browse files
authored
Change pattern to avoid deprecated render method. (#89)
1 parent 14aac2c commit bfe0742

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/Form.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ const FormikForm = ({ onUpdate, schema, ...formik }) => {
1111
* Callback if provided will be vcalled when form values change
1212
*/
1313
useEffect(() => {
14-
if(typeof onUpdate === 'function') {
14+
if (typeof onUpdate === 'function') {
1515
onUpdate(formik);
1616
}
17-
}, [ formik.values ]);
17+
}, [formik.values]);
1818

19-
return <Element config={ schema } />;
19+
return <Element config={schema} />;
2020
};
2121

22-
const Form = React.forwardRef(({ schema, onUpdate = () => {}, initialValues = {}, ...rest }, ref) => {
23-
const [ validationSchema, setValidationSchema ] = useState(null);
22+
const Form = React.forwardRef(({ schema, onUpdate = () => { }, initialValues = {}, ...rest }, ref) => {
23+
const [validationSchema, setValidationSchema] = useState(null);
2424

2525
/**
2626
* Initialize validation schema.
@@ -29,9 +29,9 @@ const Form = React.forwardRef(({ schema, onUpdate = () => {}, initialValues = {}
2929
*/
3030
const initValidationSchema = useCallback(() => {
3131
const yupSchema = prepareValidationSchema(schema);
32-
const validationSchema = !_.isEmpty(yupSchema) ? new Rules([[ 'object', yupSchema ]]).toYup() : null;
32+
const validationSchema = !_.isEmpty(yupSchema) ? new Rules([['object', yupSchema]]).toYup() : null;
3333
setValidationSchema(validationSchema);
34-
}, [ schema ]);
34+
}, [schema]);
3535

3636
/**
3737
* Everytime the schema changes, re-initialize validationSchema
@@ -42,7 +42,7 @@ const Form = React.forwardRef(({ schema, onUpdate = () => {}, initialValues = {}
4242
*/
4343
useEffect(() => {
4444
initValidationSchema();
45-
}, [ schema ]);
45+
}, [schema]);
4646

4747
const formProps = { ...rest, initialValues };
4848
if (null !== validationSchema) {
@@ -52,16 +52,17 @@ const Form = React.forwardRef(({ schema, onUpdate = () => {}, initialValues = {}
5252
return (
5353
<SchemaProvider value={{ validationSchema, schema }}>
5454
<Formik
55-
{ ...formProps }
56-
innerRef={ ref }
57-
render={(props) => (
55+
{...formProps}
56+
innerRef={ref}
57+
>
58+
{(props) => (
5859
<FormikForm
59-
onUpdate={ onUpdate }
60-
schema={ schema }
61-
{ ...props }
60+
onUpdate={onUpdate}
61+
schema={schema}
62+
{...props}
6263
/>
6364
)}
64-
/>
65+
</Formik>
6566
</SchemaProvider>
6667
);
6768
});

0 commit comments

Comments
 (0)