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.
can you guide me on how to use the error-boundary library the right way. I’ve read the docu but can’t quite achieve what i want:
Basically i want to handle errors, if OFL_TB is not a valid path. First i tried to wrap the MSM into the ErrorBoundary, that did not work out. Then i tried wrapping the locations where i am using TürOberfläche and wrapping it into ErrorBoundary, that worked. Here is how i use it in a basic mesh:
The problem with this is that i get this warning for the setOFT_TB: TestUV.jsx:53 Warning: Cannot update during an existing state transition (such as within render). Render methods should be a pure function of props and state.
The other thing i want to achieve is displaying an UI Error component i already created but that does not work with this approach…