News for hackers. Stuff that matters.
Re:React Renderer for Three.js by CraftThatBlock on Sunday August 15, 2021 @02:51PM (#28191342)
I'm guessing they are overloading the ref's usage with the custom renderer. I believe that a renderer can accept non-function/class components in theory, which is why this works.

I don't really like this though, although interesting, it feels like a hack and might not integrate well with tooling (e.g. the Typescript example).

How I would have implemented it was exposition a Mesh component which wraps this, and a useMesh hook to wrap and type the ref.

Re:React Renderer for Three.js by mlsarecmg on Sunday August 15, 2021 @03:41PM (#28191823)
r3f is a custom renderer, there is no difference in useRef between a div or a mesh, refs give you the underlying object. lowercase elements are native elements (div, span, mesh, view, box), they are defined by the renderer. uppercase is for components.
Re:React Renderer for Three.js by tills13 on Sunday August 15, 2021 @03:45PM (#28191866)
Ah, if they're using a custom JSX Pragma it might make sense. Still a little too bespoke for me.
Re:React Renderer for Three.js by mlsarecmg on Sunday August 15, 2021 @03:53PM (#28191937)
no special jsx pragma needed. this is actually just plain react, <div> <span> and so on come from react-dom, which defines these elements. other renderers define theirs. here's a mini custom renderer if this interests you: https://codesandbox.io/s/reurope-reconciler-hd16y
Re:React Renderer for Three.js by yashap on Sunday August 15, 2021 @03:26PM (#28191666)
Yeah, I don’t have experience with this lib, but the example code looks overly magic. But I’m also more of a backend dev, and find the useRef API to be inherently confusing, so that’s probably part of it.