From 204bc9a924076e0fddf58c0e2d9aa6362d0bdc51 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Mon, 5 Aug 2024 14:02:43 +0300 Subject: [PATCH 1/5] Actualize t helper providing and prop-types --- src/ui/LedgersCategorySelect/LedgersCategorySelect.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ui/LedgersCategorySelect/LedgersCategorySelect.js b/src/ui/LedgersCategorySelect/LedgersCategorySelect.js index 10b5f5ca9..18cb48f99 100644 --- a/src/ui/LedgersCategorySelect/LedgersCategorySelect.js +++ b/src/ui/LedgersCategorySelect/LedgersCategorySelect.js @@ -1,6 +1,6 @@ import React from 'react' import PropTypes from 'prop-types' -import { withTranslation } from 'react-i18next' +import { useTranslation } from 'react-i18next' import _memoize from 'lodash/memoize' import Select from 'ui/Select' @@ -46,9 +46,9 @@ const LedgersCategorySelect = (props) => { const { className, onChange, - t, value, } = props + const { t } = useTranslation() return ( ) From 87c1181e28621d9c62b36638e6b53a75a54f0159 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Mon, 5 Aug 2024 14:07:59 +0300 Subject: [PATCH 4/5] Optimize exporting --- src/ui/LedgersCategorySelect/LedgersCategorySelect.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/ui/LedgersCategorySelect/LedgersCategorySelect.js b/src/ui/LedgersCategorySelect/LedgersCategorySelect.js index 6f9a313ed..f2c37a82a 100644 --- a/src/ui/LedgersCategorySelect/LedgersCategorySelect.js +++ b/src/ui/LedgersCategorySelect/LedgersCategorySelect.js @@ -1,4 +1,4 @@ -import React from 'react' +import React, { memo } from 'react' import PropTypes from 'prop-types' import { useTranslation } from 'react-i18next' import _memoize from 'lodash/memoize' @@ -42,12 +42,7 @@ const getLedgersCategories = _memoize((t) => ([ { value: 911, label: t('ledgers.categories.losses') }, ])) -const LedgersCategorySelect = (props) => { - const { - className, - onChange, - value, - } = props +const LedgersCategorySelect = ({ className, onChange, value }) => { const { t } = useTranslation() const items = getLedgersCategories(t) @@ -73,4 +68,4 @@ LedgersCategorySelect.defaultProps = { value: '', } -export default LedgersCategorySelect +export default memo(LedgersCategorySelect) From e89e7f1ccbbbd6dff1b05286b752fefe94d950f0 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Mon, 5 Aug 2024 14:10:16 +0300 Subject: [PATCH 5/5] Rework and enhance getLedgersCategories helpers usage --- src/ui/LedgersCategorySelect/LedgersCategorySelect.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ui/LedgersCategorySelect/LedgersCategorySelect.js b/src/ui/LedgersCategorySelect/LedgersCategorySelect.js index f2c37a82a..69cecc4b4 100644 --- a/src/ui/LedgersCategorySelect/LedgersCategorySelect.js +++ b/src/ui/LedgersCategorySelect/LedgersCategorySelect.js @@ -1,11 +1,10 @@ -import React, { memo } from 'react' +import React, { memo, useMemo } from 'react' import PropTypes from 'prop-types' import { useTranslation } from 'react-i18next' -import _memoize from 'lodash/memoize' import Select from 'ui/Select' -const getLedgersCategories = _memoize((t) => ([ +const getLedgersCategories = (t) => [ { value: '', label: t('selector.all') }, { value: 5, label: t('ledgers.categories.exchange') }, { value: 22, label: t('ledgers.categories.position_modified') }, @@ -40,11 +39,11 @@ const getLedgersCategories = _memoize((t) => ([ { value: 905, label: t('ledgers.categories.currency_conversion') }, { value: 907, label: t('ledgers.categories.monthly_profit_payment') }, { value: 911, label: t('ledgers.categories.losses') }, -])) +] const LedgersCategorySelect = ({ className, onChange, value }) => { const { t } = useTranslation() - const items = getLedgersCategories(t) + const items = useMemo(() => getLedgersCategories(t), [t]) return (