Languages
[Edit]
EN

React - radio button example (controlled components)

3 points
Created by:
Rubi-Reyna
677

In this article we would like to show you how to use React radio button.

Quick solution:

 

Practical example

Edit

Below example shows a form as a functional component with two radio buttons representing Male and Female.

With useState we are able to keep the data in component's state. In our case it's one of two genders: male or female. When onChange event occurs then setGender updates the state of a component the selected radio button's value.

JSX version:

Important note:
When you create forms, React recommends using uncontrolled components,
because with controlled components large amount of input elements with onChange event handling leads to performance degradation by component multiple re-rendering.

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

ReactJS

React - radio button example
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join