Skip to content

Commit

Permalink
Bring 6.27.0 docs updates into main
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Oct 22, 2024
1 parent 230181d commit 38a0c29
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 96 deletions.
8 changes: 3 additions & 5 deletions docs/components/form.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface FormProps
reloadDocument?: boolean;
replace?: boolean;
state?: any;
unstable_viewTransition?: boolean;
viewTransition?: boolean;
}
```

Expand Down Expand Up @@ -281,11 +281,9 @@ If you are using [`<ScrollRestoration>`][scrollrestoration], this lets you preve

See also: [`<Link preventScrollReset>`][link-preventscrollreset]

## `unstable_viewTransition`
## `viewTransition`

The `unstable_viewTransition` prop enables a [View Transition][view-transitions] for this navigation by wrapping the final state update in `document.startViewTransition()`. If you need to apply specific styles for this view transition, you will also need to leverage the [`unstable_useViewTransitionState()`][use-view-transition-state].

<docs-warning>Please note that this API is marked unstable and may be subject to breaking changes without a major release</docs-warning>
The `viewTransition` prop enables a [View Transition][view-transitions] for this navigation by wrapping the final state update in `document.startViewTransition()`. If you need to apply specific styles for this view transition, you will also need to leverage the [`useViewTransitionState()`][use-view-transition-state].

# Examples

Expand Down
19 changes: 8 additions & 11 deletions docs/components/link.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface LinkProps
reloadDocument?: boolean;
replace?: boolean;
state?: any;
unstable_viewTransition?: boolean;
viewTransition?: boolean;
}

type To = string | Partial<Path>;
Expand Down Expand Up @@ -171,24 +171,23 @@ let { state } = useLocation();

The `reloadDocument` property can be used to skip client side routing and let the browser handle the transition normally (as if it were an `<a href>`).

## `unstable_viewTransition`
## `viewTransition`

The `unstable_viewTransition` prop enables a [View Transition][view-transitions] for this navigation by wrapping the final state update in `document.startViewTransition()`:
The `viewTransition` prop enables a [View Transition][view-transitions] for this navigation by wrapping the final state update in `document.startViewTransition()`:

```jsx
<Link to={to} unstable_viewTransition>
<Link to={to} viewTransition>
Click me
</Link>
```

If you need to apply specific styles for this view transition, you will also need to leverage the [`unstable_useViewTransitionState()`][use-view-transition-state] hook (or check out the `transitioning` class and `isTransitioning` render prop in [NavLink][navlink]):
If you need to apply specific styles for this view transition, you will also need to leverage the [`useViewTransitionState()`][use-view-transition-state] hook (or check out the `transitioning` class and `isTransitioning` render prop in [NavLink][navlink]):

```jsx
function ImageLink(to) {
const isTransitioning =
unstable_useViewTransitionState(to);
const isTransitioning = useViewTransitionState(to);
return (
<Link to={to} unstable_viewTransition>
<Link to={to} viewTransition>
<p
style={{
viewTransitionName: isTransitioning
Expand All @@ -212,9 +211,7 @@ function ImageLink(to) {
}
```

<docs-warning>`unstable_viewTransition` only works when using a data router, see [Picking a Router][picking-a-router]</docs-warning>

<docs-warning>Please note that this API is marked unstable and may be subject to breaking changes without a major release</docs-warning>
<docs-warning>`viewTransition` only works when using a data router, see [Picking a Router][picking-a-router]</docs-warning>

[link-native]: ./link-native
[scrollrestoration]: ./scroll-restoration
Expand Down
12 changes: 4 additions & 8 deletions docs/components/nav-link.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ When a `NavLink` is active it will automatically apply `<a aria-current="page">`

The `reloadDocument` property can be used to skip client side routing and let the browser handle the transition normally (as if it were an `<a href>`).

## `unstable_viewTransition`
## `viewTransition`

The `unstable_viewTransition` prop enables a [View Transition][view-transitions] for this navigation by wrapping the final state update in `document.startViewTransition()`. By default, during the transition a `transitioning` class will be added to the `<a>` element that you can use to customize the view transition.
The `viewTransition` prop enables a [View Transition][view-transitions] for this navigation by wrapping the final state update in `document.startViewTransition()`. By default, during the transition a `transitioning` class will be added to the `<a>` element that you can use to customize the view transition.

```css
a.transitioning p {
Expand All @@ -138,7 +138,7 @@ a.transitioning img {
```

```jsx
<NavLink to={to} unstable_viewTransition>
<NavLink to={to} viewTransition>
<p>Image Number {idx}</p>
<img src={src} alt={`Img ${idx}`} />
</NavLink>
Expand All @@ -147,7 +147,7 @@ a.transitioning img {
You may also use the `className`/`style` props or the render props passed to `children` to further customize based on the `isTransitioning` value.

```jsx
<NavLink to={to} unstable_viewTransition>
<NavLink to={to} viewTransition>
{({ isTransitioning }) => (
<>
<p
Expand All @@ -173,9 +173,5 @@ You may also use the `className`/`style` props or the render props passed to `ch
</NavLink>
```

<docs-warning>
Please note that this API is marked unstable and may be subject to breaking changes without a major release.
</docs-warning>

[aria-current]: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current
[view-transitions]: https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API
6 changes: 2 additions & 4 deletions docs/hooks/use-fetcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,9 @@ If you find yourself calling this function inside of click handlers, you can pro

<docs-info>Any `fetcher.load` calls that are active on the page will be re-executed as part of revalidation (either after a navigation submission, another fetcher submission, or a `useRevalidator()` call)</docs-info>

#### `options.unstable_flushSync`
#### `options.flushSync`

The `unstable_flushSync` option tells React Router DOM to wrap the initial state update for this `fetcher.load` in a [`ReactDOM.flushSync`][flush-sync] call instead of the default [`React.startTransition`][start-transition]. This allows you to perform synchronous DOM actions immediately after the update is flushed to the DOM.

<docs-warning>Please note that this API is marked unstable and may be subject to breaking changes without a major release</docs-warning>
The `flushSync` option tells React Router DOM to wrap the initial state update for this `fetcher.load` in a [`ReactDOM.flushSync`][flush-sync] call instead of the default [`React.startTransition`][start-transition]. This allows you to perform synchronous DOM actions immediately after the update is flushed to the DOM.

### `fetcher.submit()`

Expand Down
20 changes: 8 additions & 12 deletions docs/hooks/use-navigate.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ interface NavigateOptions {
state?: any;
preventScrollReset?: boolean;
relative?: RelativeRoutingType;
unstable_flushSync?: boolean;
unstable_viewTransition?: boolean;
flushSync?: boolean;
viewTransition?: boolean;
}

type RelativeRoutingType = "route" | "path";
Expand Down Expand Up @@ -114,21 +114,17 @@ new URL("..", window.origin + location.pathname + "/");
// 'https://remix.run/docs/en/main/start/'
```

## `options.unstable_flushSync`
## `options.flushSync`

The `unstable_flushSync` option tells React Router DOM to wrap the initial state update for this navigation in a [`ReactDOM.flushSync`][flush-sync] call instead of the default [`React.startTransition`][start-transition]. This allows you to perform synchronous DOM actions immediately after the update is flushed to the DOM.
The `flushSync` option tells React Router DOM to wrap the initial state update for this navigation in a [`ReactDOM.flushSync`][flush-sync] call instead of the default [`React.startTransition`][start-transition]. This allows you to perform synchronous DOM actions immediately after the update is flushed to the DOM.

<docs-warning>`unstable_flushSync` only works when using a data router, see [Picking a Router][picking-a-router]</docs-warning>
<docs-warning>`flushSync` only works when using a data router, see [Picking a Router][picking-a-router]</docs-warning>

<docs-warning>Please note that this API is marked unstable and may be subject to breaking changes without a major release</docs-warning>
## `options.viewTransition`

## `options.unstable_viewTransition`
The `viewTransition` option enables a [View Transition][view-transitions] for this navigation by wrapping the final state update in `document.startViewTransition()`. If you need to apply specific styles for this view transition, you will also need to leverage the [`useViewTransitionState()`][use-view-transition-state].

The `unstable_viewTransition` option enables a [View Transition][view-transitions] for this navigation by wrapping the final state update in `document.startViewTransition()`. If you need to apply specific styles for this view transition, you will also need to leverage the [`unstable_useViewTransitionState()`][use-view-transition-state].

<docs-warning>`unstable_viewTransition` only works when using a data router, see [Picking a Router][picking-a-router]</docs-warning>

<docs-warning>Please note that this API is marked unstable and may be subject to breaking changes without a major release</docs-warning>
<docs-warning>`viewTransition` only works when using a data router, see [Picking a Router][picking-a-router]</docs-warning>

[link]: ../components/link
[redirect]: ../fetch/redirect
Expand Down
8 changes: 3 additions & 5 deletions docs/hooks/use-submit.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,11 @@ Because submissions are navigations, the options may also contain the other navi
- `relative`
- `replace`
- `state`
- `unstable_viewTransition`
- `viewTransition`

### `options.unstable_flushSync`
### `options.flushSync`

The `unstable_flushSync` option tells React Router DOM to wrap the initial state update for this submission in a [`ReactDOM.flushSync`][flush-sync] call instead of the default [`React.startTransition`][start-transition]. This allows you to perform synchronous DOM actions immediately after the update is flushed to the DOM.

<docs-warning>Please note that this API is marked unstable and may be subject to breaking changes without a major release</docs-warning>
The `flushSync` option tells React Router DOM to wrap the initial state update for this submission in a [`ReactDOM.flushSync`][flush-sync] call instead of the default [`React.startTransition`][start-transition]. This allows you to perform synchronous DOM actions immediately after the update is flushed to the DOM.

[pickingarouter]: ../routers/picking-a-router
[form]: ../components/form
Expand Down
15 changes: 7 additions & 8 deletions docs/hooks/use-view-transition-state.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
title: unstable_useViewTransitionState
title: useViewTransitionState
---

# `unstable_useViewTransitionState`
# `useViewTransitionState`

<details>
<summary>Type declaration</summary>

```tsx
declare function unstable_useViewTransitionState(
declare function useViewTransitionState(
to: To,
opts: { relative?: "route" : "path" } = {}
): boolean;
Expand All @@ -24,17 +24,16 @@ interface Path {

</details>

This hook returns `true` when there is an active [View Transition][view-transitions] to the specified location. This can be used to apply finer-grained styles to elements to further customize the view transition. This requires that view transitions have been enabled for the given navigation via the [unstable_viewTransition][link-view-transition] prop on the `Link` (or the `Form`, `navigate`, or `submit` call).
This hook returns `true` when there is an active [View Transition][view-transitions] to the specified location. This can be used to apply finer-grained styles to elements to further customize the view transition. This requires that view transitions have been enabled for the given navigation via the [viewTransition][link-view-transition] prop on the `Link` (or the `Form`, `navigate`, or `submit` call).

Consider clicking on an image in a list that you need to expand into the hero image on the destination page:

```jsx
function NavImage({ src, alt, id }) {
const to = `/images/${id}`;
const isTransitioning =
unstable_useViewTransitionState(to);
const isTransitioning = useViewTransitionState(to);
return (
<Link to={to} unstable_viewTransition>
<Link to={to} viewTransition>
<img
src={src}
alt={alt}
Expand All @@ -49,5 +48,5 @@ function NavImage({ src, alt, id }) {
}
```

[link-view-transition]: ../components/link#unstable_viewtransition
[link-view-transition]: ../components/link#viewtransition
[view-transitions]: https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API
Loading

0 comments on commit 38a0c29

Please sign in to comment.