464 karma · joined May 7, 2016
it allows you to create self-contained components. that alone will eradicate so much boilerplate and complexity. it has a real pointer event system. it takes care of managing the scene reactively, it disposes of objects it does not need any longer.
you use this for the same reason you would use react for the dom. r3f is not a wrapper that duplicates the threejs export catalogue, it is a renderer/reconciler.
The problem is essentially the same. Native apps are also conflicted with load, they have better means than we have on the web to deal with it, but it's still low-level and complex to orchestrate, threading for instance. Any one of those means pushes your app into async issuee, race conditions that you need to reconcile. With concurrent mode scheduling is a first class concept, your components won't be subject to race conditions. React maintains 60fps, high-priority content (user input, animations, transitions) can be ran fluidly while lesser priority content gets deferred. It has a good chance of outperforming multithreaded native apps with that model.
This demo illustrates the issue: https://youtu.be/nLF0n9SACd4?t=172 which is universal. You run into this on native platforms as well as on the web.
With what React is attempting currently your app will render as much as it possibly can while maintaining stable 60fps, the rest gets deferred while it can differ between lesser and higher-priority updates. If you doubt how important scheduling is, look at practically any feasible list component, they're all virtualized. With React every aspect and corner of the application is like that. In theory it could outperform native apps.
Btw, there are countless of robust desktop apps being made with HTML: VSC, Whatsapp, Skype, Spotify, Notion, Hyper, Discord, Slack, ... thought most of them will still feel sluggish compared to a native counterpart. React will change that.
Class lifecycles being replaced by hooks is a radical but much needed change. Learning it isn't complicated and it will enable you to venture on as everything around you sheds the class based component approach. Swiftui, Vue, Svelte and ofc React are just the beginning.
with concurrent mode i think of what could be, web applications that can compete against native for the first time. as well as making making components that are resilient to async issues / making async a high level concept. there's a little churn for sure (for library devs, and a specific subset), but imo completely worth it.
useFrame binds a single component to the render-loop. But in a managed way. Once the component unmount, it's getting taken out. You can also stack calls like that with something like a z-index, which is awesome for effects.
This game uses some of it: https://codesandbox.io/embed/react-three-fiber-untitled-game...
Or some of the other demos here: https://github.com/react-spring/react-three-fiber
React lends extremely well to games, especially with hooks. Now you have reactive components, but also algebraic effects.
It contrasts how web frameworks and even native frameworks work. Native has prioritizing and occlusion, but i know nothing that schedules as deeply as this.
The demo in particular schedules a react renderer for threejs (https://github.com/drcmda/react-three-fiber). But it applies to any other target as well.
React is hard to stop at this point as it swept over to other platforms. If it really gets to drive platforms with a single component standard and a unified events system, on the web, ios, android, windows, mac, linux, then i don't think a web framework will hold against this much longer tbh.
It never did squish styles into a monolith. Strangely, that is exactly what Vue does with SFC, do you use Vue without?
And the small node tool that converts GLTF blobs into reactive, declarative markup: https://github.com/react-spring/react-three-fiber/tree/3.x/t...
{condition && <div>hello</div>}
The div is there as long as the condition is true. But of course it can now also be a mesh, or a component that can clean itself up after the unmount.We did this manually before, which usually meant watching out for objects to remove themselves, they'll have to communicate up their hierarchy to inform parents and so on. This wasn't straight forward in three, so there was a lot of prototype hacking and terrible things like that, i'm so glad this will be all gone.
The benefit of using tags (jsx) is that objects become fully managed. The most clear indication to me is still effects. https://codesandbox.io/embed/mo0xrqrj79 You can drop that in and it works. Make it conditional and once it gets unmounted the render loop goes back to normal. Almost magic, but then again, react for the dom had the same benefits.