Fixed typo

This commit is contained in:
2020-03-03 17:25:51 +01:00
parent ae6bee329f
commit 46b5b428c1
2 changed files with 11 additions and 7 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ const schema = yup.object().shape({
});
const BookForm = () => {
const [titleProps, setTitle] = useFormField("author");
const [titleProps, setTitle] = useFormField("title");
const [authorProps, setAuthor] = useFormField("author");
const [addBook, { loading }] = useMutation(AddBook);
+10 -6
View File
@@ -1,4 +1,4 @@
import { useState } from 'haunted';
import { useState, useCallback } from 'haunted';
type FormField = [
{
@@ -7,18 +7,22 @@ type FormField = [
'.value': string;
'@change': (e: any) => void;
},
(value: string) => void
ReturnType<typeof useState>[1]
];
export const useFormField = (name: string, defaultValue = ""): FormField => {
const [value, setValue] = useState(defaultValue);
const changeHandler = (e: any) => {
const changeHandler = useCallback((e: any) => {
setValue(e.target.value);
};
}, [setValue]);
return [
{ name, type: "text", '.value': value, '@change': changeHandler },
{
name,
type: "text",
'.value': value,
'@change': changeHandler
},
setValue
];
};