Git Product home page Git Product logo

Comments (6)

asparagii avatar asparagii commented on May 12, 2024 10
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.

asparagii avatar asparagii commented on May 12, 2024 8

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.

jhartquist avatar jhartquist commented on May 12, 2024 3

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.

drcmda avatar drcmda commented on May 12, 2024

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.

ryanking1809 avatar ryanking1809 commented on May 12, 2024

Got it, thanks! I just didn't understand how it knew to make an svg component vs a three component

from react-three-fiber.

drcmda avatar drcmda commented on May 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.