Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS migration] Migrate 'SectionList' component to TypeScript #29745

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
BartoszGrajdek marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, {forwardRef} from 'react';
import {SectionList} from 'react-native';
import {SectionList as RNSectionList} from 'react-native';
import ForwardedSectionList from './types';

const SectionListWithRef = forwardRef((props, ref) => (
<SectionList
// eslint-disable-next-line react/function-component-definition
const SectionListWithRef: ForwardedSectionList = (props, ref) => (
<RNSectionList
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={ref}
Expand All @@ -11,8 +13,8 @@ const SectionListWithRef = forwardRef((props, ref) => (
// eslint-disable-next-line react/jsx-props-no-multi-spaces
removeClippedSubviews
/>
));
);

SectionListWithRef.displayName = 'SectionListWithRef';

export default SectionListWithRef;
export default forwardRef(SectionListWithRef);
3 changes: 0 additions & 3 deletions src/components/SectionList/index.js

This file was deleted.

16 changes: 16 additions & 0 deletions src/components/SectionList/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, {forwardRef} from 'react';
import {SectionList as RNSectionList} from 'react-native';
import ForwardedSectionList from './types';

// eslint-disable-next-line react/function-component-definition
const SectionList: ForwardedSectionList = (props, ref) => (
<RNSectionList
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={ref}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BartoszGrajdek Please make this won't create any regressions

/>
);

SectionList.displayName = 'SectionList';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we keep same name as Android one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't change it compared to the way it was before. Section list in index.js didn't have display name provided, so by default it had SectionList. On all platforms other than android SectionList component doesn't use forwardRef so it makes sense to have different displayNames

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you passed the reference.


export default forwardRef(SectionList);
9 changes: 9 additions & 0 deletions src/components/SectionList/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {ForwardedRef} from 'react';
import {SectionList, SectionListProps} from 'react-native';

type ForwardedSectionList = {
(props: SectionListProps<SectionList>, ref: ForwardedRef<SectionList>): React.ReactNode;
displayName: string;
};

export default ForwardedSectionList;
Loading