Skip to content
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
98f0166
Start v11 docs
JoviDeCroock May 24, 2025
49c85bc
refactor: Finish up initial v11 config
rschristian Jun 19, 2025
69dfbfb
chore: Adhere to new doc structure
rschristian Jun 19, 2025
d6803fc
refactor: Improve precompile-markdown parse errors
rschristian Jun 19, 2025
cb8c3dd
docs: Work on Upgrade Guide
rschristian Jun 19, 2025
da11e95
docs: Revise replaceNode change
rschristian Jun 19, 2025
7fd9c36
docs: Add note on px suffixing
rschristian Jun 19, 2025
3b60dda
docs: Correct ref forward hook instructions
rschristian Jun 22, 2025
3bf6b6e
docs: Move browser support note to 'About' page
rschristian Jun 26, 2025
2417864
docs: Remove mention of the 'replaceNode' param in API docs
rschristian Jun 26, 2025
b5f7f85
refactor: Drop removed 'external dom mutations' page from config
rschristian Jun 26, 2025
1c2e89a
docs: Bring back browser version note
rschristian Jun 26, 2025
3162e69
fix: Header styling
rschristian Jun 26, 2025
d2fa92a
docs: Continue to flesh out upgrade guide
rschristian Jun 26, 2025
a7ab5e7
docs: Add note on Hydration 2.0
rschristian Jul 9, 2025
d6db3e8
docs: Mention new use of 'Object.is' for hooks
rschristian Jul 9, 2025
b27d9af
fix: Page titles
rschristian Jul 9, 2025
d9aec61
refactor: Merge whats-new and upgrade-guide for v11
rschristian Jul 16, 2025
5a71b90
refactor: Walk back making v11 already the default
rschristian Jul 31, 2025
e3ad036
fix: Prerender v11 docs
rschristian Jul 31, 2025
e736ea6
docs: Update 'replaceNode' removal to mention 'preact-root-fragment'
rschristian Jul 31, 2025
bda3fd8
chore: Remove v11 tutorial, mirroring removal in v10
rschristian Jul 31, 2025
9f702a9
docs: Correct message on 'forwardRef' changes
rschristian Jul 31, 2025
3f44653
docs: Update TS information for extending interfaces
rschristian Aug 10, 2025
23f62ea
docs: Add TS section to v11 upgrade guide
rschristian Aug 10, 2025
bdbdee1
Merge branch 'master' into refactor/v11-docs
JoviDeCroock Aug 19, 2025
8670ed5
Update src/components/controllers/guide-page.jsx
JoviDeCroock Aug 19, 2025
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
11 changes: 9 additions & 2 deletions content/en/about/browser-support.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
---
title: Browser Support
description: Preact supports all modern browsers (Chrome, Firefox, Safari, Edge) and IE11 out of the box
description: Preact supports all modern browsers (Chrome, Firefox, Safari, Edge) out of the box
---

# Browser Support

Preact supports modern browsers (Chrome, Firefox, Safari, Edge) and IE11. It works out of the box with these browsers and no additional polyfills are needed.
Preact 11.x supports the following browsers out of the box with no additional polyfills needed:

- Chrome >= 40
- Safari >= 9
- Firefox >= 36
- Edge >= 12

If you need to support older browsers, you can use polyfills or stick to Preact 10.x which supports back to IE11.
205 changes: 205 additions & 0 deletions content/en/guide/v11/api-reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
---
title: API Reference
description: Learn more about all exported functions of the Preact module
---

# API Reference

This page serves as a quick overview over all exported functions.

---

<toc></toc>

---

## Component

`Component` is a base class that can be extended to create stateful Preact components.

Rather than being instantiated directly, Components are managed by the renderer and created as-needed.

```js
import { Component } from 'preact';

class MyComponent extends Component {
// (see below)
}
```

### Component.render(props, state)

All components must provide a `render()` function. The render function is passed the component's current props and state, and should return a Virtual DOM Element (typically a JSX "element"), an Array, or `null`.

```jsx
import { Component } from 'preact';

class MyComponent extends Component {
render(props, state) {
// props is the same as this.props
// state is the same as this.state

return <h1>Hello, {props.name}!</h1>;
}
}
```

To learn more about components and how they can be used, check out the [Components Documentation](/guide/v10/components).

## render()

`render(virtualDom, containerNode)`

Render a Virtual DOM Element into a parent DOM element `containerNode`. Does not return anything.

```jsx
// --repl
// DOM tree before render:
// <div id="container"></div>

import { render } from 'preact';

const Foo = () => <div>foo</div>;

render(<Foo />, document.getElementById('container'));

// After render:
// <div id="container">
// <div>foo</div>
// </div>
```

The first argument must be a valid Virtual DOM Element, which represents either a component or an element. When passing a Component, it's important to let Preact do the instantiation rather than invoking your component directly, which will break in unexpected ways:

```jsx
const App = () => <div>foo</div>;

// 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

// DO: Passing components using h() or JSX allows Preact to render correctly:
render(h(App), rootElement); // success
render(<App />, rootElement); // success
```

## hydrate()

If you've already pre-rendered or server-side-rendered your application to HTML, Preact can bypass most rendering work when loading in the browser. This can be enabled by switching from `render()` to `hydrate()`, which skips most diffing while still attaching event listeners and setting up your component tree. This works only when used in conjunction with pre-rendering or [Server-Side Rendering](/guide/v10/server-side-rendering).

```jsx
// --repl
import { hydrate } from 'preact';

const Foo = () => <div>foo</div>;
hydrate(<Foo />, document.getElementById('container'));
```

## h() / createElement()

`h(type, props, ...children)`

Returns a Virtual DOM Element with the given `props`. Virtual DOM Elements are lightweight descriptions of a node in your application's UI hierarchy, essentially an object of the form `{ type, props }`.

After `type` and `props`, any remaining parameters are collected into a `children` property.
Children may be any of the following:

- Scalar values (string, number, boolean, null, undefined, etc)
- Nested Virtual DOM Elements
- Infinitely nested Arrays of the above

```js
import { h } from 'preact';

h('div', { id: 'foo' }, 'Hello!');
// <div id="foo">Hello!</div>

h('div', { id: 'foo' }, 'Hello', null, ['Preact!']);
// <div id="foo">Hello Preact!</div>

h('div', { id: 'foo' }, h('span', null, 'Hello!'));
// <div id="foo"><span>Hello!</span></div>
```

## toChildArray

This helper function converts a `props.children` value to a flattened Array regardless of its structure or nesting. If `props.children` is already an array, a copy is returned. This function is useful in cases where `props.children` may not be an array, which can happen with certain combinations of static and dynamic expressions in JSX.

For Virtual DOM Elements with a single child, `props.children` is a reference to the child. When there are multiple children, `props.children` is always an Array. The `toChildArray` helper provides a way to consistently handle all cases.

```jsx
import { toChildArray } from 'preact';

function Foo(props) {
const count = toChildArray(props.children).length;
return <div>I have {count} children</div>;
}

// props.children is "bar"
render(<Foo>bar</Foo>, container);

// props.children is [<p>A</p>, <p>B</p>]
render(
<Foo>
<p>A</p>
<p>B</p>
</Foo>,
container
);
```

## cloneElement

`cloneElement(virtualElement, props, ...children)`

This function allows you to create a shallow copy of a Virtual DOM Element.
It's generally used to add or overwrite `props` of an element:

```jsx
function Linkout(props) {
// add target="_blank" to the link:
return cloneElement(props.children, { target: '_blank' });
}
render(
<Linkout>
<a href="/">home</a>
</Linkout>
);
// <a href="/" target="_blank">home</a>
```

## createContext

See the section in the [Context documentation](/guide/v10/context#createcontext).

## createRef

Provides a way to reference an element or component once it has been rendered.

See the [References documentation](/guide/v10/refs#createref) for more details.

## Fragment

A special kind of component that can have children, but is not rendered as a DOM element.
Fragments make it possible to return multiple sibling children without needing to wrap them in a DOM container:

```jsx
// --repl
import { Fragment, render } from 'preact';

render(
<Fragment>
<div>A</div>
<div>B</div>
<div>C</div>
</Fragment>,
document.getElementById('container')
);
// Renders:
// <div id="container>
// <div>A</div>
// <div>B</div>
// <div>C</div>
// </div>
```
Loading