Fixed typo
This commit is contained in:
+1
-1
@@ -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
@@ -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
|
||||
];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user