I am developing a form in react native which is having radio buttons and text input and I want to save all the responses when I submit the form but I'm not able to understand how I can create an array that contain all the selected responses so that I can send to the backend.(Note using styled-components for styles)
The code looks like this
Feedback.tsx
const FeedBack = () => { const submitIcon = <Icon name="poll" size={24} color="#ffffff" />; return (<FeedBackMainContainer><MainTextContainer><MainText>we care about your valuable feedback ..!!</MainText> </MainTextContainer><CustomTextInput /> <CustomCheckBox title={"do you love gardening ?"} options={["yes", "no"]} /><CustomCheckBox title={"how many plants do you have ?"} options={["0-10", "10-20", "more than 20"]} /><CustomButton title={"Submit"} icon={submitIcon} submit={true} toPage={"Submit"} /></FeedBackMainContainer> );};
CustomCheckBox.tsx (using react-native-paper Radio button Group https://callstack.github.io/react-native-paper/radio-button-group.html)
const CustomCheckBox = ({ title, options }: Props) => { const [value, setVal] = useState(options[0]); console.log(value) return (<CheckBoxMainContainer><RadioQuestionTitle>{title}</RadioQuestionTitle><RadioButton.Group onValueChange={(val) => setVal(val)} value={value}> {options.map((item,index) => { return (<RadioOptinsContainer key={index}><RadioButton color="#1f4623" value={item} /><TextStyle>{item}</TextStyle></RadioOptinsContainer> ); })}</RadioButton.Group></CheckBoxMainContainer> );};
I am getting the selected response in value but how do I save it uniquely?