Skip to content

create hook useDevice() #595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion components/section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ComponentFunc } from "../engine/block.ts";
import { FieldResolver } from "../engine/core/resolver.ts";
import { logger } from "../observability/otel/config.ts";
import { PartialProps } from "$fresh/src/runtime/Partial.tsx";
import { Device, deviceOf } from "deco/utils/userAgent.ts";

export interface SectionContext extends HttpContext<RequestState> {
renderSalt?: string;
Expand Down Expand Up @@ -144,8 +145,17 @@ export const withSection = <TProps,>(
const idPrefix = getSectionID(ctx.resolveChain);
const debugEnabled = ctx.context?.state?.debugEnabled;
const renderSaltFromState = ctx.context?.state?.renderSalt;
const req = ctx.request;
let device: Device | null = null;

return {
props,
props: {
req,
get device() {
return device ??= deviceOf(ctx.request);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its not reusing it from ctx, why?

},
...props,
},
Component: (props: TProps) => {
// if parent salt is not defined it means that we are at the root level, meaning that we are the first partial in the rendering tree.
const parentRenderSalt = useContext(SectionContext)?.renderSalt;
Expand Down