From 266ddf2fd7d59509ae493ad74ac76a79bde33412 Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Thu, 24 Aug 2023 10:45:41 +0200 Subject: [PATCH] Migrate index.js to function component --- src/components/InvertedFlatList/index.js | 46 +++++++++++------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/src/components/InvertedFlatList/index.js b/src/components/InvertedFlatList/index.js index 923a17210af7..4cd15ba60521 100644 --- a/src/components/InvertedFlatList/index.js +++ b/src/components/InvertedFlatList/index.js @@ -1,4 +1,4 @@ -import React, {forwardRef} from 'react'; +import React, {forwardRef, useEffect} from 'react'; import PropTypes from 'prop-types'; import {FlatList, StyleSheet} from 'react-native'; import _ from 'underscore'; @@ -18,34 +18,30 @@ const propTypes = { // This is adapted from https://codesandbox.io/s/react-native-dsyse // It's a HACK alert since FlatList has inverted scrolling on web -class InvertedFlatList extends React.Component { - constructor(props) { - super(props); +function InvertedFlatList(props) { + const {innerRef, contentContainerStyle} = props; + let list; - this.list = undefined; - } - - componentDidMount() { - if (!_.isFunction(this.props.innerRef)) { + useEffect(() => { + if (!_.isFunction(innerRef)) { // eslint-disable-next-line no-param-reassign - this.props.innerRef.current = this.list; + innerRef.current = list; } else { - this.props.innerRef(this.list); + innerRef(list); } - } - - render() { - return ( - (this.list = el)} - shouldMeasureItems - contentContainerStyle={StyleSheet.compose(this.props.contentContainerStyle, styles.justifyContentEnd)} - /> - ); - } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + return ( + (list = el)} + shouldMeasureItems + contentContainerStyle={StyleSheet.compose(contentContainerStyle, styles.justifyContentEnd)} + /> + ); } InvertedFlatList.propTypes = propTypes;