Skip to content

Commit

Permalink
Initialize sections with a value
Browse files Browse the repository at this point in the history
  • Loading branch information
paultsimura committed Feb 27, 2024
1 parent 8e816ff commit b39957f
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/components/OptionsSelector/BaseOptionsSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ function BaseOptionsSelector(props) {
const accessibilityRoles = _.values(CONST.ROLE);

const [disabledOptionsIndexes, setDisabledOptionsIndexes] = useState([]);
const [sections, setSections] = useState();
const [shouldDisableRowSelection, setShouldDisableRowSelection] = useState(false);
const [errorMessage, setErrorMessage] = useState('');
const [value, setValue] = useState('');
Expand Down Expand Up @@ -137,12 +136,6 @@ function BaseOptionsSelector(props) {
return calcAllOptions;
}, [props.sections]);

// eslint-disable-next-line react-hooks/exhaustive-deps
const initialAllOptions = useMemo(() => flattenSections(), []);
const [allOptions, setAllOptions] = useState(initialAllOptions);
const [focusedIndex, setFocusedIndex] = useState(getInitiallyFocusedIndex(initialAllOptions));
const [focusedOption, setFocusedOption] = useState(allOptions[focusedIndex]);

/**
* Maps sections to render only allowed count of them per section.
*
Expand All @@ -165,6 +158,13 @@ function BaseOptionsSelector(props) {
[paginationPage, props.sections],
);

// eslint-disable-next-line react-hooks/exhaustive-deps
const initialAllOptions = useMemo(() => flattenSections(), []);
const [sections, setSections] = useState(sliceSections());
const [allOptions, setAllOptions] = useState(initialAllOptions);
const [focusedIndex, setFocusedIndex] = useState(getInitiallyFocusedIndex(initialAllOptions));
const [focusedOption, setFocusedOption] = useState(allOptions[focusedIndex]);

/**
* Completes the follow-up actions after a row is selected
*
Expand Down Expand Up @@ -346,9 +346,6 @@ function BaseOptionsSelector(props) {
[allOptions, sections],
);

// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(() => setSections(sliceSections()), []);

useEffect(() => {
subscribeToEnterShortcut();
subscribeToCtrlEnterShortcut();
Expand Down

0 comments on commit b39957f

Please sign in to comment.