ReactJS Evergreen Radio Component
Last Updated :
11 Jun, 2021
React Evergreen is a popular front-end library with a set of React components for building beautiful products as this library is flexible, sensible defaults, and User friendly. Radio Component allows the user to select one option from a set or list of items. We can use the following approach in ReactJS to use the Evergreen Radio Component.
Radio Props:
- id: It is used to denote the id attribute of the radio.
- name: It is used to define the name attribute of the radio.
- label: It is used to denote the label of the radio.
- value: It is used to denote the value attribute of the radio.
- onChange: It is a callback function that is called when the state changes.
- disabled: The radio is disabled when this is set to true.
- checked: The radio is checked when this is set to true.
- size: It is used to denote the size of the radio circle.
- isRequired: The radio gets the required attribute when this is set to true.
- isInvalid: The aria-invalid attribute is true when this is set to true.
- appearance: It is used for the appearance of the checkbox.
RadioGroup Props:
- options: It is used to pass the options for the radios of the Radio Group.
- value: It is used to denote the selected item value when controlled.
- defaultValue: It is used to denote the default value of the Radio Group when uncontrolled.
- onChange: It is a callback function that is called when the state changes.
- label: It is used to denote the label of the radio.
- size: It is used to denote the size of the radio circle.
- isRequired: The radio gets the required attribute when this is set to true.
Â
Creating React Application And Installing Module:
Step 1: Create a React application using the following command:
npx create-react-app foldername
Step 2: After creating your project folder i.e. foldername, move to it using the following command:
cd foldername
Step 3: After creating the ReactJS application, Install the required module using the following command:
npm install evergreen-ui
Project Structure: It will look like the following.
Project StructureExample: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.
App.js
import React from 'react'
import { RadioGroup } from 'evergreen-ui'
export default function App() {
const [ageGroup, setAgeGroup] = React.useState('0-10 years')
return (
<div style={{
display: 'block', width: 700, paddingLeft: 30
}}>
<h4>ReactJS Evergreen Radio Component</h4>
<RadioGroup
label="Please select your Age group"
value={ageGroup}
options={[
{ label: '0-10 years', value: '0-10 years' },
{ label: '10-20 years', value: '0-10 years' },
{ label: '20-40 years', value: '0-10 years' },
{ label: '40-60 years', value: '40-60 years' },
{ label: 'Above 60 years', value: ' Above 60 years' },
]}
onChange={e => setAgeGroup(e.target.value)}
/>
</div>
);
}
Step to Run Application: Run the application using the following command from the root directory of the project:
npm start
Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

Reference: https://evergreen.segment.com/components/radio
Similar Reads
ReactJS Evergreen Portal Component React Evergreen is a popular front-end library with a set of React components for building beautiful products as this library is flexible, sensible defaults, and User friendly. Portal Component provides a way for the user to render outside the current DOM tree. It is a simple utility component that
2 min read
ReactJS Evergreen Pagination Component React Evergreen is a popular front-end library with a set of React components for building beautiful products as this library is flexible, sensible defaults, and User friendly. Pagination Component allows the user to navigate between pages. A user can select a specific page from a range of pages. We
2 min read
ReactJS Evergreen Menu Component React Evergreen is a popular front-end library with a set of React components for building beautiful products as this library is flexible, sensible defaults, and User friendly. Menu Component allows the user to show a list of actions that the user can take. We can use the following approach in React
3 min read
ReactJS Evergreen FormField Component React Evergreen is a popular front-end library with a set of React components for building beautiful products as this library is flexible, sensible defaults, and User friendly. FormField Component allows the user to use it as a utility component to help compose form fields We can use the following a
2 min read
ReactJS Evergreen Tab Component React Evergreen is a popular front-end library with a set of React components for building beautiful products as this library is flexible, sensible defaults, and User friendly. Tab Component allows the user to switch between components present in given different tabs. It is used for organizing our c
2 min read