From 6dd835d63f106c6e1bf7a02de16d3047a5bee558 Mon Sep 17 00:00:00 2001 From: eemaanamir Date: Wed, 28 Feb 2024 22:49:26 +0500 Subject: [PATCH] refactor: converted functions to memos for best practice --- .../BulkEmailContentHistory.jsx | 10 +++++----- .../bulk-email-task-manager/BulkEmailTaskHistory.jsx | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/bulk-email-tool/bulk-email-task-manager/BulkEmailContentHistory.jsx b/src/components/bulk-email-tool/bulk-email-task-manager/BulkEmailContentHistory.jsx index 9380a33..ef0e244 100644 --- a/src/components/bulk-email-tool/bulk-email-task-manager/BulkEmailContentHistory.jsx +++ b/src/components/bulk-email-tool/bulk-email-task-manager/BulkEmailContentHistory.jsx @@ -1,6 +1,6 @@ /* eslint-disable react/no-unstable-nested-components */ -import React, { useState } from 'react'; +import React, { useMemo, useState } from 'react'; import PropTypes from 'prop-types'; import { useParams } from 'react-router-dom'; import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; @@ -51,7 +51,7 @@ function BulkEmailContentHistory({ intl }) { * up a level (the `subject` field). We also convert the `sent_to` data to be a String rather than an array to fix a * display bug in the table. */ - function transformDataForTable() { + const transformDataForTable = useMemo(() => { const tableData = emailHistoryData?.map((item) => ({ ...item, subject: item.email.subject, @@ -59,7 +59,7 @@ function BulkEmailContentHistory({ intl }) { created: new Date(item.created).toLocaleString(), })); return tableData || []; - } + }, [emailHistoryData]); /** * This function is responsible for setting the current `messageContent` state data. This will be the contents of a @@ -100,7 +100,7 @@ function BulkEmailContentHistory({ intl }) { * contents of a previously sent message. */ const additionalColumns = () => { - const tableData = transformDataForTable(); + const tableData = transformDataForTable; return [ { @@ -137,7 +137,7 @@ function BulkEmailContentHistory({ intl }) { {showHistoricalEmailContentTable ? ( { const tableData = emailTaskHistoryData?.map((item) => ({ ...item, created: new Date(item.created).toLocaleString(), })); return tableData || []; - } + }, [emailTaskHistoryData]); const tableColumns = [ { @@ -103,7 +103,7 @@ function BulkEmailTaskHistory({ intl }) { {showHistoricalTaskContentTable ? (