react-fast-hoc
Advanced tools
Comparing version
# react-fast-hoc | ||
## 0.1.2 | ||
### Patch Changes | ||
- 2245bd5: Fixed displayName prop for anonymous components and display name rewrite turned off for production enviroment | ||
## 0.1.1 | ||
@@ -4,0 +10,0 @@ |
@@ -31,2 +31,5 @@ "use strict"; | ||
// src/shared.ts | ||
var getComponentName = /* @__PURE__ */ __name((Component) => Component?.displayName ?? Component?.name ?? "UnknownComponent", "getComponentName"); | ||
// src/toFunctional.ts | ||
@@ -40,3 +43,2 @@ var import_react = require("react"); | ||
} | ||
const name = `${Component.displayName ?? Component.name ?? "Unknown"}FunctionalWrapper`; | ||
const FunctionalWrapper = (0, import_react.forwardRef)( | ||
@@ -52,5 +54,9 @@ (props, ref) => (0, import_react.createElement)( | ||
); | ||
FunctionalWrapper.displayName = name; | ||
FC_STORE.set(Component, FunctionalWrapper); | ||
FC_STORE.set(FunctionalWrapper, FunctionalWrapper); | ||
if (process.env.NODE_ENV === "production") { | ||
return FunctionalWrapper; | ||
} | ||
const name = `${getComponentName(Component)}.FunctionalWrapper`; | ||
FunctionalWrapper.displayName = name; | ||
return FunctionalWrapper; | ||
@@ -78,6 +84,9 @@ }, "_toFunctional"); | ||
get(target, p, receiver) { | ||
if (process.env.NODE_ENV === "production") { | ||
return Reflect.get(target, p, receiver); | ||
} | ||
if (p !== "displayName") { | ||
return Reflect.get(target, p, receiver); | ||
} | ||
return this.nameRewrite ?? `${this.namePrefix ?? ""}${target?.displayName ?? "UnknownComponent"}`; | ||
return this.nameRewrite ?? `${this.namePrefix ?? ""}${getComponentName(target)}`; | ||
} | ||
@@ -84,0 +93,0 @@ }; |
{ | ||
"name": "react-fast-hoc", | ||
"license": "MIT", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"sideEffects": false, | ||
@@ -29,2 +29,3 @@ "publishConfig": { | ||
"@testing-library/react": "^14.0.0", | ||
"@types/node": "^20.2.5", | ||
"@types/react": "^18.2.0", | ||
@@ -40,4 +41,4 @@ "@types/react-dom": "^18.2.0", | ||
"vitest": "^0.30.1", | ||
"eslint-config-custom": "0.0.0", | ||
"tsconfig": "0.0.0" | ||
"tsconfig": "0.0.0", | ||
"eslint-config-custom": "0.0.0" | ||
}, | ||
@@ -44,0 +45,0 @@ "peerDependencies": { |
import type { ReactNode, Ref } from "react"; | ||
import { type Get, isClassComponent, toFunctional } from "./toFunctional"; | ||
import { getComponentName } from "./shared"; | ||
import { isClassComponent, toFunctional, type Get } from "./toFunctional"; | ||
@@ -24,2 +25,5 @@ // Using classes to save memory | ||
get(target: Function, p: string | symbol, receiver: any) { | ||
if (process.env.NODE_ENV === "production") { | ||
return Reflect.get(target, p, receiver); | ||
} | ||
if (p !== "displayName") { | ||
@@ -29,6 +33,3 @@ return Reflect.get(target, p, receiver); | ||
return ( | ||
this.nameRewrite ?? | ||
`${this.namePrefix ?? ""}${ | ||
(target as { displayName?: string })?.displayName ?? "UnknownComponent" | ||
}` | ||
this.nameRewrite ?? `${this.namePrefix ?? ""}${getComponentName(target)}` | ||
); | ||
@@ -35,0 +36,0 @@ } |
import type { ComponentType } from "react"; | ||
import { Component as ReactComponent, createElement, forwardRef } from "react"; | ||
import { getComponentName } from "./shared"; | ||
@@ -16,5 +17,2 @@ export const FC_STORE = new WeakMap<object, Function>(); | ||
const name = `${ | ||
Component.displayName ?? Component.name ?? "Unknown" | ||
}FunctionalWrapper`; | ||
const FunctionalWrapper = forwardRef<Get<Props, "ref">, Props>((props, ref) => | ||
@@ -31,6 +29,11 @@ createElement( | ||
FunctionalWrapper.displayName = name; | ||
FC_STORE.set(Component, FunctionalWrapper); | ||
FC_STORE.set(FunctionalWrapper, FunctionalWrapper); | ||
if (process.env.NODE_ENV === "production") { | ||
return FunctionalWrapper; | ||
} | ||
const name = `${getComponentName(Component)}.FunctionalWrapper`; | ||
FunctionalWrapper.displayName = name; | ||
return FunctionalWrapper; | ||
@@ -37,0 +40,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
95710
3.79%25
19.05%1159
4.7%14
7.69%4
Infinity%