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 · 1 comment
Open

[v9] Make useAsset return a thenable #3411

alexandernanberg opened this issue Dec 7, 2024 · 1 comment

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'))
@krispya
Copy link
Member

krispya commented Dec 13, 2024

From Discord:

In v9 we aren't doing breaking changes, but I think this makes sense if we add a new API like loadAsset and then decide if we want to deprecate useAsset later. There is a complete overhaul of caching planned for v10 that this might lead to nicely.

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

2 participants