hey all, typescript question forgive me.. how do ...
# help
k
hey all, typescript question forgive me.. how do you write this into ts?
t
where is useFormFields coming from?
from this signature it's saying it only accepts an array of strings as input, not an object
k
import { useState } from "react"; type InputEvent = React.ChangeEvent<HTMLInputElement>; export function useFormFields(initialState : Array<string>) {   const [fields, setValues] = useState(initialState);   return [     fields,     function(event: InputEvent) {       setValues({           ...fields,           [event.target.id]: event.target.value       });     }   ]; }
thats my generic field get/setter for forms
i say my... 😄 its from the sst example stuff
t
can you link it?
initialState should be
Record<string, string>
not Array<string>
k
ahh it might have been me porting to ts incorrectly then
t
I'd suggest using react-hook-form or something if you're going to control the form state
There usually isn't a good reason to control the state of every input
k
thank you again, I will look at that instead 🙂