Skip to content
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

Update typing documentation and change disclaimer for rendering #1207

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion content/en/guide/v10/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ The first argument must be a valid Virtual DOM Element, which represents either
```jsx
const App = () => <div>foo</div>;

// DON'T: Invoking components directly breaks hooks and update ordering:
// DON'T: Invoking components directly means they won't be counted as a
// VNode and hence not be able to use functionality relating to vnodes.
render(App(), rootElement); // ERROR
render(App, rootElement); // ERROR

Expand Down
19 changes: 19 additions & 0 deletions content/en/guide/v10/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,25 @@ class Expandable extends Component<ExpandableProps, ExpandableState> {

Class components include children by default, typed as `ComponentChildren`.

## Inheriting HTML properties

When we write components like `<Input />` that wrap the HTML `<input>`, most of the time we'd want to inherit
the props that can be used on the native HTML input element. To do this we can do the following

```tsx
import { JSX } from 'preact';

type HTMLInputProperties = ;

interface InputProperties extends JSX.InputHTMLAttributes<HTMLInputElement> {
mySpecialProp: any
}

const Input = (props: InputProperties) => <input {...props} />
```

Now when we use `Input` it will know about properties like `value`, ...

## Typing events

Preact emits regular DOM events. As long as your TypeScript project includes the `dom` library (set it in `tsconfig.json`), you have access to all event types that are available in your current configuration.
Expand Down
3 changes: 2 additions & 1 deletion content/en/tutorial/01-vdom.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ in unexpected ways:
```jsx
const App = () => <div>foo</div>;

// DON'T: Invoking components directly breaks hooks and update ordering:
// DON'T: Invoking components directly means they won't be counted as a
// VNode and hence not be able to use functionality relating to vnodes.
render(App(), rootElement); // ERROR
render(App, rootElement); // ERROR

Expand Down
Loading