react-native-swipe-list-view icon indicating copy to clipboard operation
react-native-swipe-list-view copied to clipboard

SectionList typescript sections error

Open hengkx opened this issue 3 years ago • 3 comments

SectionListProps<ItemT, SectionT = DefaultSectionT>

hengkx avatar Nov 23 '20 11:11 hengkx

Hey @hengkx what is the issue? Any chance you could submit a PR to fix? Thanks!

jemise111 avatar Dec 15 '20 16:12 jemise111

@jemise111

I think @hengkx refer this problem:

when we use useSectionList

renderItem the argument should return follow object https://reactnative.dev/docs/sectionlist#requiredrenderitem

  • 'item' (object) - the item object as specified in this section's data key
  • 'index' (number) - Item's index within the section.
  • 'section' (object) - The full section object as specified in sections.
  • 'separators' (object) - An object with the following keys:
    • 'highlight' (function) - () => void
    • 'unhighlight' (function) - () => void
    • 'updateProps' (function) - (select, newProps) => void
      • 'select' (enum) - possible values are 'leading', 'trailing'
      • 'newProps' (object)
<SwipeListView
  useSectionList
  renderItem={({item, section}) => { // TS Error:  Property 'section' does not exist on type 'ListRenderItemInfo '.
    return <ItemShowingLayout item={item} />;
  }}
/>

tmirun avatar Apr 26 '21 11:04 tmirun

That's correct as i'm facing the same exact issue as described by @tmirun, while waiting for a fix. Is there a short term fix to convert the data from ListRenderItemInfo to SectionListRenderItemInfo. Something like:

<SwipeListView
            {...props}
            useSectionList
            renderItem={(data, rowMap): ReactElement => {
                    const sectionData = { ...data } as SectionListRenderItemInfo<T>  //<---- Something like this?
                    return renderItem({ sectionData, rowMap })
                }
            }
/>

then in your renderItem() can specify the type to be SectionListRenderItemInfo<T> instead

alexcbluk avatar Jun 17 '21 13:06 alexcbluk