Use useCallback instead of binding anonymous function

This commit is contained in:
Paul Kaplan 2021-04-01 09:23:42 -04:00
parent b8b56fff61
commit ead57013e3

View file

@ -1,4 +1,4 @@
import React, {useEffect} from 'react';
import React, {useEffect, useCallback} from 'react';
import PropTypes from 'prop-types';
import {useParams} from 'react-router-dom';
import {connect} from 'react-redux';
@ -18,6 +18,11 @@ const StudioComments = ({
replies
}) => {
const {studioId} = useParams();
const handleLoadComments = useCallback(() => {
getTopLevelComments(studioId, comments.length);
}, [studioId, comments.length]);
useEffect(() => {
if (comments.length === 0) getTopLevelComments(studioId, 0);
}, [studioId]);
@ -49,8 +54,7 @@ const StudioComments = ({
{moreCommentsToLoad &&
<Button
className="button load-more-button"
// eslint-disable-next-line react/jsx-no-bind
onClick={() => getTopLevelComments(studioId, comments.length)}
onClick={handleLoadComments}
>
<FormattedMessage id="general.loadMore" />
</Button>