Skip to content
Merged
Changes from all commits
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: 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;
}