Skip to content

Commit 67e22cf

Browse files
Better hydration
1 parent a4311a2 commit 67e22cf

2 files changed

Lines changed: 40 additions & 12 deletions

File tree

‎app/routes/make/accessibility-preview.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export async function loader(args: Parameters<LoaderFunction>[0]) {
3939
}
4040

4141
export default function MakeRenderer() {
42-
let data: Await<ReturnType<typeof loader>> = useRouteData();
42+
const data: Await<ReturnType<typeof loader>> = useRouteData();
4343

4444
const outputHTML = Array.from(processHTML(HTMLComponent)).join("");
4545
const outputJAWS = Array.from(previewJAWS(HTMLComponent)).join("\n");

‎app/routes/make/schema.tsx‎

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import type { MetaFunction, LinksFunction, LoaderFunction } from "remix";
1+
import {
2+
MetaFunction,
3+
LinksFunction,
4+
LoaderFunction,
5+
useRouteData,
6+
} from "remix";
27
import { X, Y } from "../../view/structure";
38
import { NamedSection } from "../../view/semantics";
49
import { CodeBlock } from "../../view/code";
@@ -10,6 +15,8 @@ import {
1015
read,
1116
SchemaGenerator,
1217
} from "../../model/schemas";
18+
import { formatJavaScript } from "../../view/codeFormatting";
19+
import { Await } from "../../types/helpers";
1320

1421
export let meta: MetaFunction = () => {
1522
return {
@@ -22,9 +29,20 @@ export let links: LinksFunction = () => {
2229
return [];
2330
};
2431

25-
export let loader: LoaderFunction = async () => {
26-
return {};
27-
};
32+
export async function loader(args: Parameters<LoaderFunction>[0]) {
33+
return {
34+
source: {
35+
components: {
36+
ProfileSchema: formatJavaScript(ProfileSchema.toString()),
37+
AWSRegionSchema: formatJavaScript(AWSRegionSchema.toString()),
38+
},
39+
functions: {
40+
parseFormData: formatJavaScript(parseFormData.toString()),
41+
parseJSON: formatJavaScript(parseJSON.toString()),
42+
},
43+
},
44+
};
45+
}
2846

2947
function useFetch<Data>(source: URL): null | Data {
3048
const [data, setData] = useState<Data | null>(null);
@@ -105,6 +123,8 @@ function* SwapiPersonResource(): SchemaGenerator<SwapiPersonData> {
105123
}
106124

107125
export default function MakeRenderer() {
126+
const data: Await<ReturnType<typeof loader>> = useRouteData();
127+
108128
function renderExample(input: any): JSX.Element {
109129
const result = parseJSON(input, AWSRegionSchema);
110130

@@ -124,31 +144,39 @@ export default function MakeRenderer() {
124144
favoriteNumber: 7,
125145
});
126146

127-
const personDataRaw: any = useFetch(new URL(`https://swapi.py4e.com/api/people/1`));
128-
const personData = personDataRaw != null ? parseJSON(personDataRaw, SwapiPersonSchema) : null;
129-
// const personData = personDataRaw;
147+
const personDataRaw: any = useFetch(
148+
new URL(`https://swapi.py4e.com/api/people/1`)
149+
);
150+
const personData =
151+
personDataRaw != null ? parseJSON(personDataRaw, SwapiPersonSchema) : null;
130152

131153
return (
132154
<main data-measure="center">
133155
<h1>Schema</h1>
134156

135157
<h2>JSON</h2>
136-
<CodeBlock language="javascript">{parseJSON.toString()}</CodeBlock>
158+
<CodeBlock language="javascript">
159+
{data.source.functions.parseJSON}
160+
</CodeBlock>
137161

138162
<h2>Form Data</h2>
139-
<CodeBlock language="javascript">{parseFormData.toString()}</CodeBlock>
163+
<CodeBlock language="javascript">
164+
{data.source.functions.parseFormData}
165+
</CodeBlock>
140166

141167
<NamedSection id="aws-region-schema" heading={<h2>AWS Region Schema</h2>}>
142168
<CodeBlock language="javascript">
143-
{AWSRegionSchema.toString()}
169+
{data.source.components.AWSRegionSchema}
144170
</CodeBlock>
145171

146172
<h3>Results</h3>
147173
{renderExample({ primary: "us", secondary: "east", digit: 1 })}
148174
</NamedSection>
149175

150176
<NamedSection id="profile-form" heading={<h2>Profile Form</h2>}>
151-
<CodeBlock language="javascript">{ProfileSchema.toString()}</CodeBlock>
177+
<CodeBlock language="javascript">
178+
{data.source.components.ProfileSchema}
179+
</CodeBlock>
152180

153181
<h3>Interactive Preview</h3>
154182
<form

0 commit comments

Comments
 (0)