score:1

Accepted answer

there is a workaround to force it to convert to a boolean, something like this:

      <select
        {...register("isactive", {
          setvalueas: (v) => boolean(v)
        })}
      >
        <option value={true}>active</option> //boolean("any string") gives true
        <option value={""}>inactive</option> //boolean("") gives false
      </select>

setvalueas returns the input value by running it through a function, and since the input produce string at submitting, the only way to force it to make it boolean is by passing an empty string.

score:0

for some reason i can't comment, big brain stackoverflow, ok however.

erm, since you're storing as a string, i recommend attaching the value to a string, then have a useeffect run with the state as a dependency setting your own personal state that is a boolean. for example

useeffect(() => {setmystate(value === "isactive" ? true : false)}, [value])

i'm having a bit too big of a brain fart, ima just imitate it.

const component = () => {
  // your component, let's say you have these two states
  const [linkedstate, setlinkedstate] = usestate("")
  const [booleanstate, setbooleanstate] = usestate("")
  // this state is linked to the string value, you then make a 
  useeffect with the state as dependency
  useeffect(() => {
    // this happens when linkedstate changes
    setbooleanstate(linkedstate === "isactive" ? true : false)
    // if linkedstate equals isactive it sets your boolean to true, else it goes false
   }, [linkedstate])
}

Related Query

More Query from same tag