Mojang / ore-ui

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

Make it possible to supply an initial value for useFacetRef #103

Closed creativecreature closed 1 year ago

creativecreature commented 1 year ago

Overview

Reacts useRef allows you to supply a default value. When using useFacetRef it can get a little verbose to have to check it against NO_VALUE.

const mockFacet: Facet<string> ....
const ref = useFacetRef(mockFacet) // MutableRefObject<Option<string>>
const mockFacet: Facet<string> ....
const ref = useFacetRef(mockFacet, 'fallback') // MutableRefObject<string>