Home > Enterprise >  Is there a way to make HTML buttons act like radio buttons with React?
Is there a way to make HTML buttons act like radio buttons with React?

Time:04-02

I have a group of <buttons> that I would like to act similarly to radio buttons. When a button is clicked, I need it to stay active, and when another button in that set is clicked, it needs to be made inactive and the new button needs to become active. I am using React.

I've tried different solutions and none have worked. Is there a way to do it with vanilla JS or React? Should I just use jQuery?

CodePudding user response:

You can try some npm package that provides Radio Componenet to achieve this. You can search for packages and use the one you like. I am currently using Mantine which provides a lot of React components.

However, This is the one that I made. Take a look at it. Here is the link. https://codesandbox.io/s/cold-water-ij5bfx?file=/src/App.js.

  • Related