Skip to content

Commit a941a6a

Browse files
authored
Merge pull request #29745 from software-mansion-labs/ts-migration/section-list-component
[TS migration] Migrate 'SectionList' component to TypeScript
2 parents 63875ad + 533bbd2 commit a941a6a

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import React, {forwardRef} from 'react';
2-
import {SectionList} from 'react-native';
2+
import {SectionList as RNSectionList} from 'react-native';
3+
import ForwardedSectionList from './types';
34

4-
const SectionListWithRef = forwardRef((props, ref) => (
5-
<SectionList
5+
// eslint-disable-next-line react/function-component-definition
6+
const SectionListWithRef: ForwardedSectionList = (props, ref) => (
7+
<RNSectionList
68
// eslint-disable-next-line react/jsx-props-no-spreading
79
{...props}
810
ref={ref}
@@ -11,8 +13,8 @@ const SectionListWithRef = forwardRef((props, ref) => (
1113
// eslint-disable-next-line react/jsx-props-no-multi-spaces
1214
removeClippedSubviews
1315
/>
14-
));
16+
);
1517

1618
SectionListWithRef.displayName = 'SectionListWithRef';
1719

18-
export default SectionListWithRef;
20+
export default forwardRef(SectionListWithRef);

src/components/SectionList/index.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/components/SectionList/index.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React, {forwardRef} from 'react';
2+
import {SectionList as RNSectionList} from 'react-native';
3+
import ForwardedSectionList from './types';
4+
5+
// eslint-disable-next-line react/function-component-definition
6+
const SectionList: ForwardedSectionList = (props, ref) => (
7+
<RNSectionList
8+
// eslint-disable-next-line react/jsx-props-no-spreading
9+
{...props}
10+
ref={ref}
11+
/>
12+
);
13+
14+
SectionList.displayName = 'SectionList';
15+
16+
export default forwardRef(SectionList);

src/components/SectionList/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {ForwardedRef} from 'react';
2+
import {SectionList, SectionListProps} from 'react-native';
3+
4+
type ForwardedSectionList = {
5+
(props: SectionListProps<SectionList>, ref: ForwardedRef<SectionList>): React.ReactNode;
6+
displayName: string;
7+
};
8+
9+
export default ForwardedSectionList;

0 commit comments

Comments
 (0)