#useActionData<typeof action>() not inferring Zod parsed api response

1 messages · Page 1 of 1 (latest)

subtle spoke
#

my useActionData in my index is not inferring the types parsed in action function

export async function action({request}: ActionFunctionArgs) {
    const parsedData = rootSchema.parse(responseData)
    return json(parsedData)
  } catch (error) {
    console.error(error)
    return json({error: 'Internal Server Error'}, 500)
  }
}
naive apex
#

Are you by any chance importing react router methods instead of remix/react?

subtle spoke
olive schooner
#

does this only happen when you use Zod?

#

because the error says useActionData doesn't expect any generic

#

and it's receiving one

#

the useActionData from RR doesn't accept generics

#

but the one from Remix does accept one generic

#

that's why @naive apex asked if you're by any chance importing it from RR instead of Remix

#

the hook will still work to get the action data but it won't accept the generic, that's basically the only change

subtle spoke