Skip to content

Commit 6f396cf

Browse files
Fix confusing useTransition documentation example
Removed isPending state handling from TabButton component and updated its usage.
1 parent 7f6848b commit 6f396cf

1 file changed

Lines changed: 22 additions & 17 deletions

File tree

‎src/content/reference/react/useTransition.md‎

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -653,13 +653,10 @@ export default function TabContainer() {
653653
import { useTransition } from 'react';
654654

655655
export default function TabButton({ action, children, isActive }) {
656-
const [isPending, startTransition] = useTransition();
656+
const [, startTransition] = useTransition();
657657
if (isActive) {
658658
return <b>{children}</b>
659659
}
660-
if (isPending) {
661-
return <b className="pending">{children}</b>;
662-
}
663660
return (
664661
<button onClick={async () => {
665662
startTransition(async () => {
@@ -818,7 +815,6 @@ export default function TabButton({ action, children, isActive }) {
818815
if (isActive) {
819816
return <b>{children}</b>
820817
}
821-
822818
return (
823819
<button onClick={() => {
824820
startTransition(async () => {
@@ -947,20 +943,29 @@ export default function TabContainer() {
947943
}
948944
```
949945
950-
```js src/TabButton.js
946+
import { useTransition } from 'react';
947+
951948
export default function TabButton({ action, children, isActive }) {
952-
if (isActive) {
953-
return <b>{children}</b>
954-
}
955-
return (
956-
<button onClick={() => {
957-
action();
958-
}}>
959-
{children}
960-
</button>
961-
);
949+
const [isPending, startTransition] = useTransition();
950+
951+
if (isActive) {
952+
return <b>{children}</b>;
962953
}
963-
```
954+
955+
if (isPending) {
956+
return <b className="pending">{children}</b>;
957+
}
958+
959+
return (
960+
<button onClick={() => {
961+
startTransition(async () => {
962+
await action();
963+
});
964+
}}>
965+
{children} </button>
966+
);
967+
}
968+
964969
965970
```js src/AboutTab.js hidden
966971
export default function AboutTab() {

0 commit comments

Comments
 (0)