Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to save the value of selected radio, so that when I am submitting the form I can send all the selected responses

$
0
0

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?

the form look like this


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>