Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
23 replies
MagerX

Should I condense my hooks output array?

Hey guys,

so I have my useValidation function and it returns the following array.

return [sync, isPropertyValid, watch, update, focus];



So 5 items in the array, but it seems like generally speaking the first 2 are the ones most frequently used like so

export default function Home() {
  const [syncInput, isPropertyValid] = useValidation(AccountValidation);

  return (
    <>
        <input
          {...syncInput("username")}
          style={{
            border: !isPropertyValid("username")
              ? "thick double red"
              : "thick double rgba(0,0,0,0)",
          }}
          type={"text"}
          placeholder={"Enter your name"}
        />
    </>
  );
}


Should I condense my 5 item array into something smaller like this
const actions = {watch, update, focus}

return [sync, isPropertyValid, actions];


Or do you think its better to leave it as 5?
Was this page helpful?