Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v9] Make useAsset return a thenable #3411

Open
alexandernanberg opened this issue Dec 7, 2024 · 0 comments
Open

[v9] Make useAsset return a thenable #3411

alexandernanberg opened this issue Dec 7, 2024 · 0 comments

Comments

@alexandernanberg
Copy link
Contributor

alexandernanberg commented Dec 7, 2024

Currently useAsset suspends by itself. While this is fine for most cases, but there are cases where you want more control. My proposal is that useAsset instead return a Thenable which consumers unwrap with use().

E.g.

const assetPromise = useAsset(GLTFLoader, '/path/to/model.glb')
const asset = use(assetPromise)

or a one-liner

const asset = use(useAsset(GLTFLoader, '/path/to/model.glb'))

Note that I we do this, useAsset doesn't really need to be a hook any more. So we could even do something like

const asset = use(loadAsset(GLTFLoader, '/path/to/model.glb'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant