-
Notifications
You must be signed in to change notification settings - Fork 155
Using react-three-renderer with Typescript #127
Comments
My error was due to using wrong THREE version, so that is resolved. I also managed to get TS compile errors to be reduced significantly by adding the following to my code:
Note that Typescript treats component names in JSX with lowercase as 'intrinsic', ie. expects them to be HTML and not React components. I still have an error on compiling about missing module "react-three-component" but Webpack is including it and my app is running. Perhaps others can add Typescript specific help/workarounds to this thread. Would be good to see first class Typescript support at some point! |
Regarding lower case components being html perhaps we could extend the Currently the main priority of the project is to have full feature On Thu, Nov 17, 2016, 20:57 jugglingcats [email protected] wrote:
|
I agree it would be great to have prop/attribute validation and auto-complete in the IDE and this is one of the main benefits of using Typescript IMO. I am not sure adding elements to JSX.IntrinsicElements is the way to go, because of possible conflicts with other libs (you would effectively be polluting a shared namespace). I think ultimately you might consider providing initial-caps versions of react-three-renderer components, ie. Scene, PerspectiveCamera and so on. These could either be used as Just my 2p |
For info I already found a name clash: It runs :) but compiler and IDE complain :( |
I think things would need to be context sensitive somehow as new renderers emerge. Could do an annotation to a file or the render function for example to specify what sort of renderer will be used for a component. |
I don't understand very much about renderers, but presumably a single component could use React3 and SVG, eg:
|
That's a bad component that should be split in half and deserves multiple On Fri, Nov 18, 2016, 11:48 jugglingcats [email protected] wrote:
|
Heheh. I tend to agree! I thought more about what you said and I think what you need is a way to say "The React3 component doesn't contain JSX.IntrinsicElements but instead contains React3.IntrinsicElements". That would be a nice solution. |
I just came across this thread. I came up with a slightly different approach that doesn't involve having to extend First, I we have to import
...and I defined
I'm sure there is more, but this is all I'm using so far. Then you have the issue of getting that stuff out of
Now you've got a component that the TS compiler recognizes as a first class component. This means you can then do:
Now this may seem like a lot of work. But like I said, I'm not sure it is any more work than writing a normal Thoughts? |
Interesting approach...! I assume it works fine when you have nested react-three-renderer components, even though you are introducing an intermediate element into the component tree? There would be a small performance overhead but I don't see this being an issue. I guess one disadvantage is that this would likely be a separate project and cannot easily become a first class citizen, ie. part of the react-three-renderer project in the way that I just posted this question to SO as a last attempt to find a "pure" solution: http://stackoverflow.com/questions/43493059/react-typescript-custom-renderer-and-jsx-intrinsicelements. If we adopt this approach, would you be willing to host the project...? Or maybe @toxicFork would be willing to make it a companion project to react-three-renderer. |
The intermediate elements don't really seem to cause any problems with the exception of I agree, there is a small overhead. Note that, as far as I can tell, anytime you'd like to group things into reusable components, you'd introduce just about the same overhead. I'm just forcing each leaf in the tree to be a reusable component. There is both the overhead of the function call as well as the overhead of traversing a deeper tree. Perhaps there are other concerns as well. I'm not sure how the "mounting" vs. "rendering" stuff is handled internally in R3R. My hope is that it is using the virtual DOM approach to optimize (i.e., minimize) manipulations of the 3D scene. If so, that might help. If not, then it would perhaps amplify any inefficiencies introduced here. You are correct that it would probably be a separate project. You could, of course, include all this in R3R itself. But I'm guessing the author doesn't want that headache. I would have preferred the As for "hosting" it, I'd certainly be willing to make it publicly available. I make no promises on completeness or maintenance. I don't expect to be using this extensively in the future. So I can't say I'd be able to do all the greens keeping some might expect. Perhaps @toxicFork can chime in with his opinions before we really make any decisions here. |
Cool solutions :) I would prefer a comment / I think it would be good to have it as a separate project if possible (so you will have authority over it, issues for it won't be lost in normal r3r issues, and so on), then we can consider merging it into R3R when the time comes. |
FYI, I actually gave up on my wrapper stuff. It wasn't that it was technically unsound. I just ended up opting for something that interacted directly with the THREE api rather than representing the data declaratively in JSX. |
This doesn't appear to be straightforward given the lack of @types for this lib. I have tried to force it in and ignore the typescript compiler warnings but get the following error:
Are there any plans to provide support for Typescript? Or are there any workarounds perhaps?
Thanks
The text was updated successfully, but these errors were encountered: