Skip to content

Commit

Permalink
Update docs to use json() in client loaders/actions for proper type i…
Browse files Browse the repository at this point in the history
…nference
  • Loading branch information
brophdawg11 committed Dec 12, 2023
1 parent 75aaebd commit d376bfd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions docs/guides/client-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function clientLoader({
request,
}: ClientLoaderFunctionArgs) {
const data = await fetchApiFromClient({ request }); // (2)
return data;
return json(data);
}
```

Expand Down Expand Up @@ -76,10 +76,10 @@ export async function clientLoader({
serverLoader(),
getClientData(request),
]);
return {
return json({
...serverData, // (4)
...clientData, // (4)
};
});
}
clientLoader.hydrate = true; // (3)

Expand Down Expand Up @@ -129,10 +129,10 @@ export async function clientLoader({
serverLoader(),
getClientData(request),
]);
return {
return json({
...serverData, // (4)
...clientData, // (4)
};
});
}
// Note: you do not have to set this explicitly - it is implied if there is no `loader`
clientLoader.hydrate = true;
Expand Down Expand Up @@ -195,17 +195,17 @@ export async function clientLoader({
isInitialRequest = false;
const serverData = await serverLoader();
cache.set(cacheKey, serverData); // (2)
return serverData;
return json(serverData);
}

const cachedData = await cache.get(cacheKey);
if (cachedData) {
return cachedData; // (3)
return json(cachedData); // (3)
}

const serverData = await serverLoader();
cache.set(cacheKey, serverData);
return serverData;
return json(serverData);
}
clientLoader.hydrate = true; // (2)

Expand All @@ -216,7 +216,7 @@ export async function clientAction({
const cacheKey = generateKey(request);
cache.delete(cacheKey); // (4)
const serverData = await serverAction();
return serverData;
return json(serverData);
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/route/client-action.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const clientAction = async ({
}: ClientActionFunctionArgs) => {
invalidateClientSideCache();
const data = await serverAction();
return data;
return json(data);
};
```

Expand Down
4 changes: 2 additions & 2 deletions docs/route/client-loader.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const clientLoader = async ({
// And/or fetch data on the client
const data = getDataFromClient();
// Return the data to expose through useLoaderData()
return data;
return json(data);
};
```

Expand Down Expand Up @@ -47,7 +47,7 @@ export async function loader() {
export async function clientLoader() {
// During client-side navigations, we hit our exposed API endpoints directly
const data = await fetchDataFromApi();
return data;
return json(data);
}

export default function Component() {
Expand Down

0 comments on commit d376bfd

Please sign in to comment.