Browse Source

Fixed typo

master
Anthony Hinsinger 6 years ago
parent
commit
46b5b428c1
  1. 2
      src/web/bookform.ts
  2. 16
      src/web/myhooks.ts

2
src/web/bookform.ts

@ -13,7 +13,7 @@ const schema = yup.object().shape({ @@ -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);

16
src/web/myhooks.ts

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
import { useState } from 'haunted';
import { useState, useCallback } from 'haunted';
type FormField = [
{
@ -7,18 +7,22 @@ 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
];
};

Loading…
Cancel
Save