Skip to content

How to use parseAsJson with yup? #873

Answered by franky47
JSFTI asked this question in Q&A
Discussion options

You must be logged in to vote

I see, from looking at the Yup validateSync code, it needs binding to the schema instance to keep the this reference:

const [yupValidateSync, setYupValidateSync] = useQueryState(
  'yupValidateSync',
  parseAsJson(yupSchema.validateSync.bind(yupSchema))
)

Note that yupSchema.validate will not work as it returns a Promise (and nuqs parsers are synchronous).

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by JSFTI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants