Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

disabling few buttons from group of buttons React

I have an array of data

const projectTypeValues = [
{ name: 'Hour', value: 'hour'},
{ name: 'Day', value: 'day'},
{ name: 'Session', value: 'session'},
{ name: 'project', value: 'project'}]

From there I am showing the buttons in a material ui buttonGroup through an loop.

{projectTypeValues.map(element=>
          <Button variant="contained" color="primary">{element.name}</Button>
        )}

how do i make a couple or few buttons from this loop disabled while others are active?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I want to show all the 4buttons but other 3 buttons will be disabled and only session will be active

Thanks for your help

>Solution :

Try like this

{
    projectTypeValues.map(element => (
        <Button
            variant="contained"
            color="primary"
            disabled={element.value !== "session"}
        >
            {element.name}
        </Button>
    ));
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading