diff --git a/components/ChipsSelector.tsx b/components/ChipsSelector.tsx index 0a4eca4..e594ffe 100644 --- a/components/ChipsSelector.tsx +++ b/components/ChipsSelector.tsx @@ -3,7 +3,6 @@ import { View, Text, TextInput, - TouchableOpacity, StyleSheet, Button, ColorValue, @@ -25,27 +24,40 @@ const ChipInputModal = ({ const color: ColorValue = useMemo(() => showModal[1], [showModal]); const colorIdx = useMemo(() => colors.indexOf(color), [color]); - const value: number = useMemo( - () => totalChipsCount[colorIdx], - [totalChipsCount, colorIdx] - ); + const [value, setValue] = useState(); // value may be undefined initially + + // Reset the color value when the specific color this modal is for, changes. The same modal is shared/reused in all cases. + useEffect(() => { + setValue(totalChipsCount[colorIdx]); + }, [colorIdx]); return ( setShowModal([false, color])} > - Number of {showModal[1]?.toString()} chips - { - const n = parseInt(v); - update(showModal[1], Number.isNaN(n) ? 0 : n); + {value !== undefined && ( + <> + Number of {showModal[1]?.toString()} chips + { + const dirtyNum: number = parseInt(v); + !isNaN(dirtyNum) ? setValue(dirtyNum) : setValue(0); + }} + testID="modalInput" + /> + + )} +