pmndrs / drei

🥉 useful helpers for react-three-fiber
https://drei.pmnd.rs/
MIT License
7.83k stars 642 forks source link

`useTexture(..., onLoad)` callback receives incorrect values #1969

Open jwueller opened 1 month ago

jwueller commented 1 month ago

Problem description:

The types declare that the callback receives the same type that's returned from the hook itself. However, that's not the case, and it will never receive a record object.

Relevant code:

const returnedTextures = useTexture(
    {map: 'color.jpg', normalMap: 'normal.png'},
    (callbackTextures) => {
        // callbackTextures can never be an object here, and always produces and
        // array, as opposed to returnedTextures, which correctly adheres to the
        // declared type.
    },
);

Suggested solution:

Fix the callback to adhere to the declared type. I will provide a PR for this.