Mojang / ore-ui

💎 Building blocks to construct game UIs using web tech.
https://react-facet.mojang.com/
MIT License
409 stars 18 forks source link

Support defaultReturnValue in useFacetCallback #105

Closed pirelenito closed 1 year ago

pirelenito commented 1 year ago

The motivation is to make it easier to use callbacks constructed via the hook useFacetCallback to interoperate with other libraries.

As an example, before this change we will get a type error if we plan to use the resulting callback as a prop to a component that expects a string as a return type:

Type '() => string | unique symbol' is not assignable to type '() => string'.
  Type 'string | unique symbol' is not assignable to type 'string'.
    Type 'typeof import("c:/dev/minecraft-ui/node_modules/@react-facet/core/dist/types").NO_VALUE' is not assignable to type 'string'.ts(2322)

The new defaultReturnValue prop allow us to have a callback that can never return NO_VALUE.