Skip to content

Commit c1a41b4

Browse files
authored
web-components-if-you-must
1 parent 3fe0677 commit c1a41b4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/jsx/react.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,27 @@ ReactDOM.render(
260260
document.getElementById("root")
261261
);
262262
```
263+
264+
## Declaring a webcomponent
265+
266+
If you are using a web component the default React type definitions (`@types/react`) will not know about it. But you can declare it easily e.g. to declare a webcomponent called `my-awesome-slider` that takes Props `MyAwesomeSliderProps` you would:
267+
268+
```tsx
269+
declare global {
270+
namespace JSX {
271+
interface IntrinsicElements {
272+
'my-awesome-slider': MyAwesomeSliderProps;
273+
}
274+
275+
interface MyAwesomeSliderProps extends React.Attributes {
276+
name: string;
277+
}
278+
}
279+
}
280+
```
281+
282+
Now you can use it in TSX:
283+
284+
```tsx
285+
<my-awesome-slider name='amazing'/>
286+
```

0 commit comments

Comments
 (0)