Skip to content

Commit b518730

Browse files
committed
fix: use inner displayName as default
1 parent 7113df3 commit b518730

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"name": "react-context-toolbox",
2+
"name": "@restart/context",
33
"version": "2.0.2",
44
"main": "lib/index.js",
55
"module": "lib/es/index.js",
66
"types": "index.d.ts",
77
"repository": {
88
"type": "git",
9-
"url": "https://github.com/4Catalyzer/react-context-toolbox.git"
9+
"url": "https://github.com/react-restart/context"
1010
},
1111
"author": "4Catalyzer",
1212
"license": "MIT",
@@ -42,9 +42,6 @@
4242
]
4343
},
4444
"jest": {
45-
"roots": [
46-
"<rootDir>/test"
47-
],
4845
"testEnvironment": "jsdom",
4946
"setupFiles": [
5047
"<rootDir>/test/index.js"

src/forwardRef.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ import React from 'react';
22

33
export default function forwardRef(
44
renderFn,
5-
{ displayName, propTypes, defaultProps, allowFallback = false },
5+
{
6+
propTypes,
7+
defaultProps,
8+
allowFallback = false,
9+
displayName = renderFn.name || renderFn.displayName,
10+
} = {},
611
) {
712
const render = (props, ref) => renderFn(props, ref);
8-
9-
Object.assign(render, { displayName });
13+
render.displayName = displayName;
1014

1115
if (React.forwardRef || !allowFallback)
1216
return Object.assign(React.forwardRef(render), {

test/forwardRef.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react';
2+
import { mount } from 'enzyme';
3+
4+
import forwardRef from '../src/forwardRef';
5+
6+
describe('forwardRef', () => {
7+
it('should use existing displayName', () => {
8+
// eslint-disable-next-line prefer-arrow-callback
9+
const Foo = forwardRef(function Foo() {
10+
return null;
11+
});
12+
13+
expect(mount(<Foo />).find('ForwardRef(Foo)')).toHaveLength(1);
14+
});
15+
});

0 commit comments

Comments
 (0)