Skip to content

Commit

Permalink
Merge branch 'master' into 6277-tabs-nonmobile-overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblack authored Jun 23, 2020
2 parents 22139a7 + afc0642 commit 032ef98
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/react/src/internal/Selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function useSelection({
initialSelectedItems = [],
}) {
const isMounted = useRef(false);
const savedOnChange = useRef(onChange);
const [selectedItems, setSelectedItems] = useState(initialSelectedItems);
const onItemChange = useCallback(
(item) => {
Expand Down Expand Up @@ -49,10 +50,14 @@ export function useSelection({
}, [disabled]);

useEffect(() => {
if (isMounted.current === true && onChange) {
onChange({ selectedItems });
savedOnChange.current = onChange;
}, [onChange]);

useEffect(() => {
if (isMounted.current === true && savedOnChange.current) {
savedOnChange.current({ selectedItems });
}
}, [onChange, selectedItems]);
}, [selectedItems]);

useEffect(() => {
isMounted.current = true;
Expand Down

0 comments on commit 032ef98

Please sign in to comment.