diff --git a/src/constants.ts b/src/constants.ts index ce08919..208af86 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -14,6 +14,7 @@ import { useDebugValue, useDeferredValue, useTransition, + useId, } from "react"; export const hooks = Object.freeze({ @@ -52,6 +53,7 @@ export const defaultScope = { useDebugValue, useDeferredValue, useTransition, + useId, }; export const isDevelop = window.location.hostname === "localhost"; diff --git a/src/pages/useId.tsx b/src/pages/useId.tsx index 2b1ef4b..f392fc2 100644 --- a/src/pages/useId.tsx +++ b/src/pages/useId.tsx @@ -1,11 +1,73 @@ -import React, { FunctionComponent } from "react"; +import React, { FunctionComponent, useId } from "react"; import { hooks } from "../constants"; import { Layout } from "../layout/layout"; +type Props = { + title: string; + errorMessage?: string; +}; +const InputBlock = ({ title, errorMessage }: Props) => { + const errorMessageId = useId(); + + return ( +
+ + {!!errorMessage &&

{errorMessage}

} +

errorMessageId: {errorMessageId}

+
+ ); +}; + export const UseId: FunctionComponent = () => { return ( - - <> + + <> + +
+ +
); }; + +const code = ` +const InputBlock = ({ title, errorMessage }: Props) => { + const errorMessageId = useId(); + + return ( +
+ + {!!errorMessage &&

{errorMessage}

} +

errorMessageId: {errorMessageId}

+
+ ); +}; + +const UseId = () => { + return ( + <> + +
+ + + ); +}; + +render( + +) +`.trim();