Fixed typo
This commit is contained in:
+1
-1
@@ -13,7 +13,7 @@ const schema = yup.object().shape({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const BookForm = () => {
|
const BookForm = () => {
|
||||||
const [titleProps, setTitle] = useFormField("author");
|
const [titleProps, setTitle] = useFormField("title");
|
||||||
const [authorProps, setAuthor] = useFormField("author");
|
const [authorProps, setAuthor] = useFormField("author");
|
||||||
const [addBook, { loading }] = useMutation(AddBook);
|
const [addBook, { loading }] = useMutation(AddBook);
|
||||||
|
|
||||||
|
|||||||
+10
-6
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from 'haunted';
|
import { useState, useCallback } from 'haunted';
|
||||||
|
|
||||||
type FormField = [
|
type FormField = [
|
||||||
{
|
{
|
||||||
@@ -7,18 +7,22 @@ type FormField = [
|
|||||||
'.value': string;
|
'.value': string;
|
||||||
'@change': (e: any) => void;
|
'@change': (e: any) => void;
|
||||||
},
|
},
|
||||||
(value: string) => void
|
ReturnType<typeof useState>[1]
|
||||||
];
|
];
|
||||||
|
|
||||||
export const useFormField = (name: string, defaultValue = ""): FormField => {
|
export const useFormField = (name: string, defaultValue = ""): FormField => {
|
||||||
const [value, setValue] = useState(defaultValue);
|
const [value, setValue] = useState(defaultValue);
|
||||||
|
const changeHandler = useCallback((e: any) => {
|
||||||
const changeHandler = (e: any) => {
|
|
||||||
setValue(e.target.value);
|
setValue(e.target.value);
|
||||||
};
|
}, [setValue]);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{ name, type: "text", '.value': value, '@change': changeHandler },
|
{
|
||||||
|
name,
|
||||||
|
type: "text",
|
||||||
|
'.value': value,
|
||||||
|
'@change': changeHandler
|
||||||
|
},
|
||||||
setValue
|
setValue
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user