I am building a dynamic list of input components and when the user presses the submit button I would like to validate the input in every component by calling a function on each component so that each component can visually show that it has failed validation.
My component is "RegularTextInput" and I build it like this where it is used:
{carRegistrationNumbers.map((value, index) => (
<RegularTextInput
// add function to a list?
/>
);
I am new to React and React Native. How would I go about doing this? In my "RegularTextInput" how would I declare that function? And in the caller, should I maintain a list/array of all the components or functions somehow, so that I can call the function in all components when I press my submit button? Am I on the wrong path completely here 🙂
Thank you
Søren
2
Answers
I am not using forms thus the
is never called. My solution was to use
and then call
to trigger the onEndEditing. That did the trick for me.
I think this would solve your problem. You have to declare the function inside the component itself.