I try to load an OBJ file stored on S3. When the file is not there the page crashes:
Is there a way to handle errors in this hook?
I will use this example in CodeSandbox React Three Fiber Boilerplate - useGLTF - CodeSandbox
Once url is not right, it will give the error “Could not load”. I was wondering if it can give me an error message, so I could show this alert, but not crash the app. Thanks.
this doesn’t look quite right, you’ve got an object as the function parameter, i may be mistaken when it comes to r3f but typically this should probably look like the following…
function Model( url ) {
const { scene } = useGLTF(url)
return <primitive object={scene} />
}
you do not normally get an overlay, this is coming from codesandbox. error boundaries is how you catch errors in react, it’s just that csb has this “feature” where they show that dialog. some bundlers do it as well. in prod you only have the fallback.