Skip to content

Commit

Permalink
fix(react): handle fetchpriority vs fetchPriority (#644)
Browse files Browse the repository at this point in the history
lolsob
  • Loading branch information
ascorbic authored Apr 28, 2024
1 parent 8fc28cf commit 6b76808
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/react/src/camelize.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import type { HTMLAttributes } from "react";
import * as React from "react";

const nestedKeys = new Set(["style"]);

export const isNewReact = "use" in React;

const fixedMap: Record<string, string> = {
srcset: "srcSet",
fetchpriority: "fetchPriority"
fetchpriority: isNewReact ? "fetchPriority" : "fetchpriority",
};

const camelize = (key: string) => {
if (key.startsWith("data-") || key.startsWith("aria-")) {
return key;
Expand All @@ -14,12 +20,12 @@ const camelize = (key: string) => {
};

export function camelizeProps<TObject extends HTMLAttributes<HTMLElement>>(
props: TObject
props: TObject,
): TObject {
return Object.fromEntries(
Object.entries(props).map(([k, v]) => [
camelize(k),
nestedKeys.has(k) && v && typeof v !== "string" ? camelizeProps(v) : v,
])
]),
) as TObject;
}

0 comments on commit 6b76808

Please sign in to comment.