Skip to content

Commit

Permalink
[fields] Replace sectionOrder state with a memoized variable
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Mar 1, 2023
1 parent 389a853 commit 4a424c2
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,10 @@ export const useFieldState = <

const sectionsValueBoundaries = React.useMemo(() => getSectionsBoundaries<TDate>(utils), [utils]);

const [sectionOrder, setSectionOrder] = React.useState(() =>
fieldValueManager.getSectionOrder(utils, localeText, format, isRTL),
const sectionOrder = React.useMemo(
() => fieldValueManager.getSectionOrder(utils, localeText, format, isRTL),
[fieldValueManager, format, isRTL, localeText, utils],
);
React.useEffect(() => {
setSectionOrder(fieldValueManager.getSectionOrder(utils, localeText, format, isRTL));
}, [fieldValueManager, format, isRTL, localeText, utils]);

const [state, setState] = React.useState<UseFieldState<TValue, TSection>>(() => {
const sections = fieldValueManager.getSectionsFromValue(
Expand Down

0 comments on commit 4a424c2

Please sign in to comment.