Comments (6)
import { extend } from 'react-three-fiber';
import { Line } from 'three';
// Add class `Line` as `Line_` to react-three-fiber's extend function. This
// makes it so that when you use <line_> in a <Canvas>, the three reconciler
// will use the class `Line`
extend({ Line_: Line });
// declare `line_` as a JSX element so that typescript doesn't complain
declare global {
namespace JSX {
interface IntrinsicElements {
'line_': ReactThreeFiber.Object3DNode<Line, typeof Line>,
}
}
}
After doing this somewhere in your application you can use <line_>
instead of <line>
and Typescript won't get confused.
from react-three-fiber.
Typescript complains about it though!
I'm trying to use fiber's <line>
, but Typescript thinks it's a JSX.IntrinsicElements.line: React.SVGProps<SVGLineElement>
, which of course is not.
Ignoring the line with a @ts-ignore
works, of course, but it's kind of annoying
from react-three-fiber.
register it as _line. unfortunately typescript thinks jsx is about the dom only, it doesnt take reconcilers into account.
Can you explain how to do this? I'm still using
// @ts-ignore
return <line geometry={geometry} material={material} {...props}></line>
Thanks!
from react-three-fiber.
You can't mix svgs and three. Everything that is inside canvas is part of the three reconciler. Everything outside is part of the dom reconciler (react-dom). You can either:
Run both side-by-side:
<Canvas>
<line /> // THREE.Line
</Canvas>
<svg>
<line /> // the dom element "line"
</svg>
Or use Three's svg renderer https://codesandbox.io/s/yq90n32zmx
This is everyday React, though, not really a limitation but the way React works.
from react-three-fiber.
Got it, thanks! I just didn't understand how it knew to make an svg component vs a three component
from react-three-fiber.
register it as _line. unfortunately typescript thinks jsx is about the dom only, it doesnt take reconcilers into account.
from react-three-fiber.
Related Issues (20)
- Primitive with children mounting / unmounting + documentation HOT 4
- This sandbox doesn't work HOT 1
- Canvas eventHandler: onWebGLContextLost, onWebGLContextRestored HOT 2
- Cannot catch error HOT 1
- Is it possible to use react-three-fiber with React-Native CLI application? HOT 1
- help: using the onPointerDown event of a` <group/>` and the event.handlers of `useThree()` together HOT 1
- Types: Removed classes from three.js are still available at R3F HOT 3
- Rendering `<Context.Consumer.Provider>` is not supported HOT 1
- R3F & StereoCamera
- Breaking changes in React experimental branch HOT 1
- Cannot read properties of undefined (reading 'boundingSphere') HOT 1
- Forced landscape HOT 1
- load gltb file show error `Uncaught Invalid typed array length: 64548` HOT 1
- Updating from 8.15.19 to 8.16.1 causes 'demand' frameloop issues with @react-spring/three HOT 2
- Rendering issue HOT 1
- How to draw 2D views in 3D Canvas with ReactNative? HOT 1
- R3F raycast hits wrong object HOT 1
- It's not possible to preventDefault on onPointerDown HOT 1
- Both example of the "drei" sampler are not working, (cant load hdr file) HOT 1
- Something wrong happens with texture that passed to JSX attribute "map" of material
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 react-three-fiber.