Skip to content

How to type a useState variable with a Fragment? + Fragments rant #9234

Answered by max-ch9i
ZakKa89 asked this question in Q&A
Discussion options

You must be logged in to vote

To pass the result of useFragment to the state use DocumentType, e.g.:

type Product = DocumentType<typeof ProductFragment>

export const AddProductForm = () => {
  const [selectedProduct, setSelectedProduct] = useState<Product>(null)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@adriangalilea
Comment options

Answer selected by ZakKa89
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants