Comments (7)
let's add it!
from drei.
users should be able to do:
useHelper<SpotLightHelper>(ref, SpotLightHelper, color)
function useHelper<T>(
ref: React.MutableRefObject<Object3D>,
proto: T,
...args: ConstructorParameters<T>
) {
from drei.
that's fine, thats how i do it as well most of the time, eventually it will annoy someone and they fix it ;-)
from drei.
Alright, I've made some progress, I'll share here before a pr as I'm not sure about some details.
https://codesandbox.io/s/r3f-use-helper-bm2qu?file=/src/use-helper.tsx
- I'm not sure how to type the arguments to the hook, the second one should be an helper constructor but I can't seem to find any type in threejs that could work for all helpers
- the rest of the arguments would be passed to the constructor, don't know if is the correct way to do it
from drei.
So, I updated the sandbox with your suggestions, still:
useHelper<BoxHelper>(mesh, BoxHelper, "cyan");
gives me a type error "Argument of type 'typeof BoxHelper' is not assignable to parameter of type 'BoxHelper'."
This is fixed using useHelper<typeof BoxHelper>(...)
( and I'm not sure if this is desirable)
in the hook I get these type errors:
Type 'T' does not satisfy the constraint 'new (...args: any) => any'
and
This expression is not constructable.
when I try to create the new helper instance.
I'm not sure if there is a simpler approach or I'm missing some piece of ts knowledge to make this work
from drei.
i dont know TS myself, but in reactthreefiber they have solved args in /src/three-types.ts maybe you find something over there
from drei.
I fixed the warning but I think that made everything too "any"ish, maybe I'll just PR now and open an issue later to have somebody more expert with TS check the typings
from drei.
Related Issues (20)
- Error when attempting to use DragControls: Uncaught TypeError: defaultControls is null HOT 5
- Inability to use onBeforeCompile with CurveModifier
- support <Text/> fontStyle Italic for chinese character
- three 0.162.0 breaks drei HOT 4
- Masking/cropping a mesh HOT 1
- Incompatible with [email protected] HOT 1
- useKTX2() seems not to work HOT 6
- Issue with Re-initializing Mesh Portal Material after Component Removal
- Splat rendering issues using @react-three/xr on an Apple Vision Pro
- Auto scale on `Image` doesn't work
- Stats component not working with the latest update (StatsImpl is not a constructor) HOT 5
- Raycast/clicks incorrectly passing through PivotControls gizmo to object behind
- How to prevent the Pivot controller from deforming
- Bounds incorrectly calculates center to be (0,0,0) on first render
- useTexture crashes if image is not valid HOT 1
- Hard to use cameraControls ? HOT 3
- Since release 9.99.3 my app breaks if I use suspend while rendering a Text component HOT 5
- MeshPortalMaterial freezes when blend is updated within a react-xr experience
- Text3D with fontStyle and fontWeight
- Safari Scrolling List of Views Jittery HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drei.