I have a button that is disabled if a state is false and the state is change if some conditions are not met on each item in an array, one of the condition is that a textfield should contain something, I check for that condition each time the text change. The condition work but each time I change the state the keyboard is dismiss. ie: each time I enter or remove the first letter of the word.
const [canSave, setCanSave] = useState<boolean>(true);
//this function is called each time one of the textfield is changed
const updateCanSave = () => {
for (let i = 0; i < currentSteps.length; i++) {
const step = currentSteps[i];
if (
(step.name.length > 0 && step.media === undefined) ||
(step.name === "" && step.media !== undefined)
) {
setCanSave(false);
break;
}
setCanSave(true);
}
};
return (
//the flatList renderItem contains many textfield and imagePicker
<FlatList
data={array}
...
ListFooterComponent={
<Button on Press={save} disable={!canSave}>Save</Button>
}
/>
)