Skip to content

Commit

Permalink
useTransition
Browse files Browse the repository at this point in the history
  • Loading branch information
mk668a committed Jul 29, 2022
1 parent a896550 commit 859f21f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
useImperativeHandle,
useDebugValue,
useDeferredValue,
useTransition,
} from "react";

export const hooks = Object.freeze({
Expand Down Expand Up @@ -50,6 +51,7 @@ export const defaultScope = {
useImperativeHandle,
useDebugValue,
useDeferredValue,
useTransition,
};

export const isDevelop = window.location.hostname === "localhost";
Expand Down
42 changes: 39 additions & 3 deletions src/pages/useTransition.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
import React, { FunctionComponent } from "react";
import React, { FunctionComponent, useState, useTransition } from "react";
import { hooks } from "../constants";
import { Layout } from "../layout/layout";

export const UseTransition: FunctionComponent = () => {
const [isPending, startTransition] = useTransition();
const [count, setCount] = useState(0);

function handleClick() {
startTransition(() => {
setCount((c: number) => c + 1);
});
}

return (
<Layout title={hooks.useTransition}>
<></>
<Layout title={hooks.useTransition} code={code}>
<>
{isPending && <p>loading</p>}
<button onClick={handleClick}>{count}</button>
</>
</Layout>
);
};

const code = `
const UseTransition = () => {
const [isPending, startTransition] = useTransition();
const [count, setCount] = useState(0);
function handleClick() {
startTransition(() => {
setCount((c: number) => c + 1);
});
}
return (
<>
{isPending && <p>loading</p>}
<button onClick={handleClick}>{count}</button>
</>
);
};
render(
<UseTransition />
)
`.trim();

0 comments on commit 859f21f

Please sign in to comment.