You need to manage a state for the toggle switch through the external button click.

This is a reference code that should get you started.

import React from "react";

export default function App() {
  const [isOn, setIsOn] = React.useState(false);

  return (
    <>
      <input
        type="checkbox"
        checked={isOn}
        onClick={(e) => setIsOn(e.target.val)}
      />
      <br />
      <button onClick={() => setIsOn((prevState) => 
!prevState)}>Toggle</button>
    </>
  );
}

This code is available here: https://codesandbox.io/s/hungry-knuth-55eh0?file=/src/App.js

Answer from MMH on Stack Overflow
🌐
MUI
mui.com › material-ui › react-toggle-button
Toggle Button React component - Material UI
To emphasize groups of related Toggle buttons, a group should share a common container. The ToggleButtonGroup controls the selected state of its child buttons when given its own value prop. ... With exclusive selection, selecting one option deselects any other.
🌐
Gdowens
gdowens.github.io › react-toggle-button
React Toggle Button
We cannot provide a description for this page right now
People also ask

Why should you choose Syncfusion React Toggle Switch Button?
Toggling between checked and unchecked states. · Support for different sizes, labels, and label positions. · Rich UI interaction and UI customization. · Simple configuration and API. · Supports all modern browsers. · Touch-friendly and responsive UI. · One of the best React Toggle Switch Button in the market that offers feature-rich UI to interact with the software. · Extensive demos and documentation to learn quickly and get started with React Toggle Switch Button.
🌐
syncfusion.com
syncfusion.com › react › toggle switch button
React Toggle Switch Button – Responsive & Customizable | Syncfusion
Where can I find the Syncfusion React Toggle Switch Button demo?
You can find our React Toggle Switch Button demo here.
🌐
syncfusion.com
syncfusion.com › react › toggle switch button
React Toggle Switch Button – Responsive & Customizable | Syncfusion
How do I get started with Syncfusion React Toggle Switch Button?
A good place to start would be our comprehensive getting started documentation.
🌐
syncfusion.com
syncfusion.com › react › toggle switch button
React Toggle Switch Button – Responsive & Customizable | Syncfusion
🌐
Syncfusion
syncfusion.com › react › toggle switch button
React Toggle Switch Button – Responsive & Customizable | Syncfusion
February 3, 2026 - The React Toggle Switch Button component is a custom HTML5 input-type checkbox component that allows you to perform a toggle (on/off) action between checked and unchecked states.
Top answer
1 of 2
1

You need to manage a state for the toggle switch through the external button click.

This is a reference code that should get you started.

import React from "react";

export default function App() {
  const [isOn, setIsOn] = React.useState(false);

  return (
    <>
      <input
        type="checkbox"
        checked={isOn}
        onClick={(e) => setIsOn(e.target.val)}
      />
      <br />
      <button onClick={() => setIsOn((prevState) => 
!prevState)}>Toggle</button>
    </>
  );
}

This code is available here: https://codesandbox.io/s/hungry-knuth-55eh0?file=/src/App.js

2 of 2
0

As the toggle switch is a component of my employer, I just use checkbox to replace in this example.

I think I can code for my question (as you can see my code shown as below) and I found why the toggle switch cannot be turned off by a button... It is because there is a bug in the toggle switch component of my employer and then I have eventually fixed the bug.

Anyway, let me show the code for this question (even it is not the answer for the fixing the bug that I really need):

import React from "react";
import "./styles.css";

export default function App() {
  const [isOn, setIsOn] = React.useState(
      { a: false , b: false, c: false }
    );

  const handleInputA = () => {
    setIsOn({ ...isOn, a: !isOn.a });
  }

  const handleInputB = (inputLabel) => {
    setIsOn({ ...isOn, b: !isOn.b });
  }

  const handleInputC = (inputLabel) => {
    setIsOn({ ...isOn, c: !isOn.c });
  }

  return (
    <>
      <input
        type="checkbox"
        checked={isOn.a}
        onClick={handleInputA}
      />a
      <br />
      <input
        type="checkbox"
        checked={isOn.b}
        onClick={handleInputB}
      />b
      <br />
      <input
        type="checkbox"
        checked={isOn.c}
        onClick={handleInputC}
      />c (The one that I want to do for this question.)
      <br />
      { isOn.c &&
        <button onClick={handleInputC}>Unselect C</button>
      }
    </>
  );
}

You may check to see the effect if you are interested: https://codesandbox.io/s/toggleswitch-tpkti

🌐
Cloudhadoop
cloudhadoop.com › home
React Button toggle on off example
December 31, 2023 - import React, { useState } from "react"; import ReactDOM from "react-dom"; const ToggleButtonOnOff = () => { const [isOff, setIsOff] = useState(true); return ( <button onClick={() => setIsOff(!isOff)}>{isOff ? "ON" : "OFF"}</button> ); }; ReactDOM.render(<ToggleButtonOnOff />, document.getElementById("root"));
🌐
npm
npmjs.com › package › react-switch
react-switch - npm
December 14, 2024 - import React, { Component } from "react"; import Switch from "react-switch"; class SwitchExample extends Component { constructor() { super(); this.state = { checked: false }; this.handleChange = this.handleChange.bind(this); } handleChange(checked) { this.setState({ checked }); } render() { return ( <label> <span>Switch with default style</span> <Switch onChange={this.handleChange} checked={this.state.checked} /> </label> ); } }
      » npm install react-switch
    
Published   Dec 14, 2024
Version   7.1.0
Find elsewhere
🌐
Medium
medium.com › @nishaadequate123 › toggle-button-in-react-js-technical-chamber-644475687eb0
Toggle Button in React JS |Technical Chamber | by Nishaadequate | Medium
July 4, 2023 - The handleToggle function is triggered when the button is clicked. It updates the value of isToggled by toggling it between true and false using the setToggle function. The button’s text is determined by the value of isToggled. If it’s true, the text will be “ON,” and if it’s false, the text will be “OFF.”
🌐
DhiWise
dhiwise.com › post › react-toggle-button-a-journey-from-creation-to-customization
Enhancing User Experience with React Toggle Buttons
October 17, 2023 - A toggle button is a component that can switch between two states, such as on and off, true and false, or selected and deselected. It's a user-friendly way to let users change a setting or attribute without needing to navigate away from the current page or open a new dialog box. In React, a toggle button can be implemented as a functional component that uses state to keep track of whether it's currently toggled on or off...
🌐
Medium
medium.com › path2code › how-react-js-toggle-button-works-99c838ae2fe1
How React.js Toggle Button Works. In this blog, I will be explaining how… | by Penny Pang | path2code | Medium
January 21, 2019 - How React.js Toggle Button Works In this blog, I will be explaining how a toggle works in React and how to create a toggle button to display plain text. 1. The Set Up Let’s create a React component …
🌐
WebOmnizz
webomnizz.com › home › reactjs › how to create a toggle/switch button in react
How to Create a Toggle/Switch Button in React | WebOmnizz
November 26, 2020 - Let’s add some global settings to make our toggle button component extendable like disable the toggle button, change the default value, change icons, callback event on state change, additional class name etc. ... Now, go to the bottom of the page and start adding the property types to ToggleButton component. import React, { useState } from 'react'; import PropTypes from 'prop-types'; const ToggleButton = () => { const [toggle, setToggle] = useState(false); const triggerToggle = () => { setToggle( !toggle ) } return( <div onChange={triggerToggle} className={`wrg-toggle ${toggle ?
🌐
Folkstalk
folkstalk.com › home › 2022 › july
React Button Toggle On Off Example
July 20, 2022 - Next create a react class, ToggleButton, that extends the React.Component. Implement the constructor method that calls the buttonClick method. The buttonClick method changes the state from ON to OFF and vice-versa.
🌐
DEV Community
dev.to › jkaplan15 › how-to-make-a-toggle-button-and-style-it-in-react-3nha
How to Make a Toggle Button and Style it in React - DEV Community
May 16, 2023 - It uses setIsToggled to toggle the value of isToggled between true and false. The return statement renders a element that displays "ON" when isToggled is true, and "OFF" when isToggled is false.
🌐
freeCodeCamp
freecodecamp.org › news › toggle-elements-in-react-using-hooks
How to Toggle an Element in React using React Hooks
April 16, 2025 - Inside of the LogicalNot.js file, we start off by: Importing the useState hook. Then we create two variables called toggle and setToggle, while setting the initial state to true. Next, inside of the jsx section, we create a button that has an onClick event handler.
🌐
Adobe React Spectrum
react-spectrum.adobe.com › react-aria › ToggleButton.html
ToggleButton – React Aria - React Spectrum Libraries
A toggle button allows a user to toggle a selection on or off, for example switching between two states or modes. ... This sets the --tint CSS variable used by the Vanilla CSS examples.
🌐
Base UI
base-ui.com › react › components › toggle
Toggle · Base UI
'use client'; import * as React from 'react'; import { Toggle } from '@base-ui/react/toggle'; import styles from './index.module.css'; export default function ExampleToggle() { return ( <div className={styles.Panel}> <Toggle aria-label="Favorite" className={styles.Button} render={(props, state) => { if (state.pressed) { return ( <button type="button" {...props}> <HeartFilledIcon className={styles.Icon} /> </button> ); } return ( <button type="button" {...props}> <HeartOutlineIcon className={styles.Icon} /> </button> ); }} /> </div> ); } function HeartFilledIcon(props: React.ComponentProps<'svg
🌐
React
legacy.reactjs.org › docs › handling-events.html
Handling Events – React
March 29, 2022 - class Toggle extends React.Component { constructor(props) { super(props); this.state = {isToggleOn: true}; // This binding is necessary to make `this` work in the callback this.handleClick = this.handleClick.bind(this); } handleClick() { this.setState(prevState => ({ isToggleOn: !prevState.isToggleOn })); } render() { return ( <button onClick={this.handleClick}> {this.state.isToggleOn ? 'ON' : 'OFF'} </button> ); } }
🌐
Medium
medium.com › @daniela.sahagun03 › create-an-on-off-switch-on-react-toggle-button-that-switches-between-views-f4667d52502f
Create an On/Off Switch on React | Toggle button that switches between views. | by Carla Sahagun | Medium
September 24, 2020 - When you create the input and a label tag, you can connect both of them with the attribute htmlFor on a React app, and only for on a HTML document. Note that the htmlFor attribute on the label, is the same as the id for the checkbox input. 2.- Let’s create the ball slider that will be moving from side to side. This one has to be inside of the label along with the words On and Off
🌐
PrimeReact
primereact.org › togglebutton
PrimeReact | React UI Component Library
ToggleButton is used to select a boolean value using a button. import { ToggleButton } from 'primereact/togglebutton'; ToggleButton is used a controlled input component with value and onChange properties. No · <ToggleButton checked={checked} onChange={(e) => setChecked(e.value)} /> Icons and Labels can be customized using onLabel, offLabel, onIcon and offIcon properties.