Skip to content

Commit

Permalink
web-components-if-you-must
Browse files Browse the repository at this point in the history
  • Loading branch information
basarat authored Feb 12, 2020
1 parent 3fe0677 commit c1a41b4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/jsx/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,27 @@ ReactDOM.render(
document.getElementById("root")
);
```
## Declaring a webcomponent
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:
```tsx
declare global {
namespace JSX {
interface IntrinsicElements {
'my-awesome-slider': MyAwesomeSliderProps;
}

interface MyAwesomeSliderProps extends React.Attributes {
name: string;
}
}
}
```
Now you can use it in TSX:
```tsx
<my-awesome-slider name='amazing'/>
```

0 comments on commit c1a41b4

Please sign in to comment.