Skip to content

Commit 421c970

Browse files
committed
dont need a callback because we habe useEffect
1 parent d3191e7 commit 421c970

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

src/components/form-library/FormLibrary.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@ import React, { useState, useEffect, createContext } from "react";
22

33
const FormContext = createContext(null);
44

5-
function MyFormLibrary({ children, initialValues, onValuesChanged, onSubmit, validate }) {
5+
function MyFormLibrary({ children, initialValues, onSubmit, validate }) {
66
const [values, updateValues] = useState(initialValues);
77
const [errors, updateErrors] = useState({});
88

9-
useEffect(() => {
10-
if (typeof onValuesChanged === 'function') {
11-
onValuesChanged(values);
12-
}
13-
}, [values]);
14-
159
function handleChange(name, value) {
1610
updateValues({
1711
...values,

src/components/form-library/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import React, { useContext } from 'react';
1+
import React, { useContext, useEffect } from 'react';
22
import { object, string } from 'yup';
33

44
import MyFormLibrary, { FormContext } from './FormLibrary';
55

66
function MyForm() {
77
const { values, errors, handleSubmit, input } = useContext(FormContext);
88

9+
useEffect(() => {
10+
console.info('values changed', values);
11+
}, [values]);
12+
913
return <form onSubmit={handleSubmit}>
1014
<div>
1115
<input
@@ -44,9 +48,6 @@ function Screen() {
4448
onSubmit={(values) => {
4549
alert('success');
4650
}}
47-
onValuesChanged={(values) => {
48-
console.info(values);
49-
}}
5051
>
5152
<MyForm/>
5253
</MyFormLibrary>;

0 commit comments

Comments
 (0)