Skip to content

Commit

Permalink
fix(npm-react): use named function in reatomComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
artalar committed Dec 8, 2024
1 parent e84e7f6 commit 13d4be3
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/npm-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export const withBatching = (ctx: Ctx): Ctx => {
}
}

const anonFnName = (() => () => {})().name

export const reatomContext = React.createContext<null | Ctx>(null)

export const useCtx = (): Ctx => {
Expand Down Expand Up @@ -217,6 +219,7 @@ export const reatomComponent = <T extends object>(
name?: string,
): ((props: T extends PropsWithCtx<infer P> ? P : T) => JSX.Element) => {
if (name) name = `Component.${name}`
else if (Component.name !== anonFnName) name = Component.name
else name = __count('Component')

let rendering = false
Expand Down

0 comments on commit 13d4be3

Please sign in to comment.