Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Dec 1, 2022
1 parent eca2736 commit 80c4983
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 11 additions & 3 deletions src/withStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,20 @@ export function createWithStyles<Theme>(params: {
* @see https://reactjs.org/docs/higher-order-components.html#convention-wrap-the-display-name-for-easy-debugging
*/
const name: string | undefined = (() => {
{
const { name: nameOrWrappedName } = params ?? {};

if (nameOrWrappedName !== undefined) {
return typeof nameOrWrappedName !== "object"
? nameOrWrappedName
: Object.keys(nameOrWrappedName)[0];
}
}

{
const displayName = (Component_ as any).displayName;

if (displayName) {
if (typeof displayName === "string" && displayName !== "") {
return displayName;
}
}
Expand All @@ -90,8 +100,6 @@ export function createWithStyles<Theme>(params: {
return name;
}
}

return params?.name;
})();

const useStyles = makeStyles<Props, any>({ ...params, name })(
Expand Down
14 changes: 11 additions & 3 deletions src/withStyles_compat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,20 @@ export function createWithStyles<Theme>(params: {
* @see https://reactjs.org/docs/higher-order-components.html#convention-wrap-the-display-name-for-easy-debugging
*/
const name: string | undefined = (() => {
{
const { name: nameOrWrappedName } = params ?? {};

if (nameOrWrappedName !== undefined) {
return typeof nameOrWrappedName !== "object"
? nameOrWrappedName
: Object.keys(nameOrWrappedName)[0];
}
}

{
const displayName = (Component_ as any).displayName;

if (displayName) {
if (typeof displayName === "string" && displayName !== "") {
return displayName;
}
}
Expand All @@ -77,8 +87,6 @@ export function createWithStyles<Theme>(params: {
return name;
}
}

return params?.name;
})();

const useStyles = makeStyles<Props, any>({ ...params, name })(
Expand Down

0 comments on commit 80c4983

Please sign in to comment.