4 changed files with 44 additions and 11 deletions
@ -0,0 +1,25 @@
@@ -0,0 +1,25 @@
|
||||
import { useState } from 'haunted'; |
||||
|
||||
type FormField = [ |
||||
{ |
||||
name: string; |
||||
type: "text"; |
||||
'.value': string; |
||||
'@change': (e: any) => void; |
||||
}, |
||||
(value: string) => void |
||||
]; |
||||
|
||||
export const useFormField = (name: string, defaultValue = ""): FormField => { |
||||
const [value, setValue] = useState(defaultValue); |
||||
|
||||
const changeHandler = (e: any) => { |
||||
setValue(e.target.value); |
||||
}; |
||||
|
||||
return [ |
||||
{ name, type: "text", '.value': value, '@change': changeHandler }, |
||||
setValue |
||||
]; |
||||
}; |
||||
|
||||
Loading…
Reference in new issue