floating-ui / popper.js.org

🍿🦉Website and Documentation for Popper and friends
https://popper.js.org
MIT License
74 stars 394 forks source link

Update index.mdx #56

Closed ShaharIlany closed 1 year ago

ShaharIlany commented 1 year ago

Add typing to useState

ShaharIlany commented 1 year ago

Hey @FezVrasta, Thanks for the quick response!

When using Typescript, The following error occurs when not providing those types:

Type 'Dispatch<SetStateAction<null>>' is not assignable to type 'LegacyRef<HTMLInputElement> | undefined'.
  Type 'Dispatch<SetStateAction<null>>' is not assignable to type '(instance: HTMLInputElement | null) => void'.
    Types of parameters 'value' and 'instance' are incompatible.
      Type 'HTMLInputElement | null' is not assignable to type 'SetStateAction<null>'.
        Type 'HTMLInputElement' is not assignable to type 'SetStateAction<null>'.
          Type 'HTMLInputElement' provides no match for the signature '(prevState: null): null'.ts(2322)

I've just started using the library and run into this issue.

And like me, many others as you might already know 😄 https://github.com/floating-ui/react-popper/issues/415 I think it's might be a good idea to add those typings or some note in this page that this could happen and how to resolve it.

FezVrasta commented 1 year ago

The example is just JavaScript, there's nothing wrong with it. If someone wants to use TypeScript they should know to use React with it, it has nothing to do with Popper itself.

BangKarlsen commented 1 year ago

I don't agree, and judging by the 82 thumbs up on the comment here https://github.com/floating-ui/react-popper/issues/415#issuecomment-821968179 I think many people would benefit from it.

FezVrasta commented 1 year ago

The world is beautiful because of its diversity.