-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: Allow intrinsic elements to vary by component #15266
Comments
+1. React Fiber should be released soon and many custom renderers will be appearing. |
Hi @RyanCavanaugh you tagged with Awaiting More Feedback a while ago. Are you wanting feedback from me as the person who raised the issue or from the typescript team? Thanks! |
It means it is awaiting more feedback from the community as a whole. It means that it isn't obvious to the core team that it is worth expending effort on this suggestion unless there is wider support from the community. (I was going to point you at the label list but it appears this one isn't listed) |
This means we'd like to hear from more people who would be helped by this feature, understand their use cases, and possibly contrast with other proposals that might solve the problem in a simpler way (or solve many other problems at once). If this feature looks like a good fit for you, please use the 👍 reaction on the original post. Comments outlining different scenarios that would be benefited from the feature are also welcomed. |
Hi :) I'm the author of react-three-renderer and would like to contribute to TypeScript's support for custom renderers if possible :) Here are a few kinds of renderers that some initial research has shown:
To go into more detail with react-three-renderer, any element that is rendered within a To extend the above example: function testRender() {
return <div>
Check out this three dimensional thing:
<div>
<React3 {/* diving into react-three-renderer domain now */ ...{}}>
<webGLRenderer width={800} height={600} antialias>
<scene>
<mesh>
<boxGeometry width={10} height={10} depth={10} />
<meshBasicMaterial
color={"FF0000"}
/>
</mesh>
</scene>
</webGLRenderer>
</React3>
</div>
</div>;
} By looking at this I can think of various potential solutions (assuming no technical limitations):
import {Ref} from "react";
declare namespace ReactThreeRenderer {
interface IBoxGeometryProps {
width: number;
height: number;
depth: number;
}
interface IReactThreeRendererElement<T> {
key?: string;
ref?: Ref<T>;
}
interface IntrinsicElements {
boxGeometry: IReactThreeRendererElement<THREE.BoxGeometry> & IBoxGeometryProps;
meshBasicMaterial: IReactThreeRendererElement<THREE.MeshBasicMaterial> & THREE.MaterialParameters;
}
}
/// <jsx-intrinsic-elements using="ReactThreeRenderer.IntrinsicElements"/>
function testRender() {
return <scene>
<mesh>
<boxGeometry width={10} height={10} depth={10} />
<meshBasicMaterial
color={"FF0000"}
/>
</mesh>
</scene>;
}
I hope it helps! Firtina. |
I think this could be handled by checking the children of intrinsic elements the same as non-intrinsic elements. I've run into a similar case where I'm leveraging JSX to do declarative xml building. I have certain constraints on child-parent relationships that are great for non-intrinsic elements, but don't appear to be type-checked for intrinsic elements. |
I also vote for this feature. The use case I would image is following: import { myModule } from '../myModule'
myModule.component({
name: 'foo',
render: () => (
<sui-button size="large">Submit</sui-button>
)
}) with interface Component {
name: string,
render: JSX.RenderFunction<{
"sui-button": {
size?: "large" | "small"
},
"other-component": {
someProp?: number
}
}>
} I guess it can possibly allow supporting directives in JSX as well |
Two possible interpretations going on here:
|
This suggestion is motivated by react-three-renderer, which creates a custom renderer for React around the THREE library, and specifically this issue: firtoz/react-three-renderer#127.
This library was not written with Typescript in mind, and uses lowercased JSX elements for children of its main
React3
component. For example:While it's possible to avoid compiler warnings by modifying
JSX.IntrinsicElements
this causes issues where there are conflicts, for exampleline
in the above example which is also an SVG element. Also, within theReact3
component it is not sensible/valid to put normal HTML elements, so it would be good to exclude these.I am following #14729 and #13618 which seem somewhat related, but don't appear to address this specific issue.
In summary, it should be possible to indicate somehow that a component uses a different set of intrinsic elements, other than
JSX.IntrinsicElements
.The text was updated successfully, but these errors were encountered: