Skip to content

Commit 0fff9d9

Browse files
author
Brian Vaughn
committed
Added more forwardRef test cases for DevTools
1 parent 24dbe85 commit 0fff9d9

File tree

2 files changed

+19
-1
lines changed
  • packages

2 files changed

+19
-1
lines changed

packages/react-devtools-shared/src/__tests__/store-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,13 @@ describe('Store', () => {
856856

857857
const MyComponent = (props, ref) => null;
858858
const FowardRefComponent = React.forwardRef(MyComponent);
859+
const FowardRefComponentWithAnonymousFunction = React.forwardRef(() => (
860+
<MyComponent />
861+
));
862+
const FowardRefComponentWithCustomDisplayName = React.forwardRef(
863+
MyComponent,
864+
);
865+
FowardRefComponentWithCustomDisplayName.displayName = 'Custom';
859866
const MemoComponent = React.memo(MyComponent);
860867
const MemoForwardRefComponent = React.memo(FowardRefComponent);
861868
const LazyComponent = React.lazy(() => fakeImport(MyComponent));
@@ -864,6 +871,8 @@ describe('Store', () => {
864871
<React.Fragment>
865872
<MyComponent />
866873
<FowardRefComponent />
874+
<FowardRefComponentWithAnonymousFunction />
875+
<FowardRefComponentWithCustomDisplayName />
867876
<MemoComponent />
868877
<MemoForwardRefComponent />
869878
<React.Suspense fallback="Loading...">

packages/react-devtools-shell/src/app/ElementTypes/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,16 @@ function FunctionComponent() {
3535

3636
const MemoFunctionComponent = memo(FunctionComponent);
3737

38-
const ForwardRefComponent = forwardRef((props, ref) => (
38+
const FowardRefComponentWithAnonymousFunction = forwardRef((props, ref) => (
3939
<ClassComponent ref={ref} {...props} />
4040
));
41+
const ForwardRefComponent = forwardRef(function NamedInnerFunction(props, ref) {
42+
return <ClassComponent ref={ref} {...props} />;
43+
});
44+
const FowardRefComponentWithCustomDisplayName = forwardRef((props, ref) => (
45+
<ClassComponent ref={ref} {...props} />
46+
));
47+
FowardRefComponentWithCustomDisplayName.displayName = 'Custom';
4148

4249
const LazyComponent = lazy(() =>
4350
Promise.resolve({
@@ -58,6 +65,8 @@ export default function ElementTypes() {
5865
<FunctionComponent />
5966
<MemoFunctionComponent />
6067
<ForwardRefComponent />
68+
<FowardRefComponentWithAnonymousFunction />
69+
<FowardRefComponentWithCustomDisplayName />
6170
<LazyComponent />
6271
</Suspense>
6372
</StrictMode>

0 commit comments

Comments
 (0)