Skip to content

Commit

Permalink
Revert "Update docs to use json() in client loaders/actions for prope…
Browse files Browse the repository at this point in the history
…r type inference"

This reverts commit d376bfd.
  • Loading branch information
brophdawg11 committed Dec 12, 2023
1 parent d376bfd commit eed4901
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 json(data);
return data;
}
```

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

Expand Down Expand Up @@ -129,10 +129,10 @@ export async function clientLoader({
serverLoader(),
getClientData(request),
]);
return json({
return {
...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 json(serverData);
return serverData;
}

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

const serverData = await serverLoader();
cache.set(cacheKey, serverData);
return json(serverData);
return 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 json(serverData);
return 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 json(data);
return 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 json(data);
return 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 json(data);
return data;
}

export default function Component() {
Expand Down

0 comments on commit eed4901

Please sign in to comment.