🌐
GitHub
github.com › GR34SE › react-switch-selector
GitHub - GR34SE/react-switch-selector: Tiny switch/toggle component for React️ ⚛
Tiny switch/toggle component for React️ ⚛. Contribute to GR34SE/react-switch-selector development by creating an account on GitHub.
Starred by 12 users
Forked by 5 users
Languages   TypeScript 92.9% | JavaScript 4.0% | HTML 3.1% | TypeScript 92.9% | JavaScript 4.0% | HTML 3.1%
🌐
MUI
mui.com › material-ui › react-switch
React Switch component - Material UI
Switches toggle the state of a single setting on or off.
🌐
npm
npmjs.com › package › react-native-switch-selector
react-native-switch-selector - npm
December 2, 2022 - <SwitchSelector initial={0} onPress={value => this.setState({ gender: value })} textColor={colors.purple} //'#7a44cf' selectedColor={colors.white} buttonColor={colors.purple} borderColor={colors.purple} hasPadding options={[ { label: "Feminino", value: "f", imageIcon: images.feminino }, //images.feminino = require('./path_to/assets/img/feminino.png') { label: "Masculino", value: "m", imageIcon: images.masculino } //images.masculino = require('./path_to/assets/img/masculino.png') ]} testID="gender-switch-selector" accessibilityLabel="gender-switch-selector" />
      » npm install react-native-switch-selector
    
🌐
CodeSandbox
codesandbox.io › s › react-switch-selector-8osrxr
React Switch Selector - CodeSandbox
October 18, 2022 - React Switch Selector by ed_Miller using react, react-dom, react-scripts, react-switch-selector
Published   Oct 18, 2022
Author   ed_Miller
🌐
Adobe
react-aria.adobe.com › Switch
Switch | React Aria
A switch allows a user to turn a setting on or off · Use the isSelected or defaultSelected prop to set the selection state, and onChange to handle selection changes
🌐
Stack Overflow
stackoverflow.com › questions › 76518867 › react-native-switch-selector
React Native Switch Selector
Here is the entire code for the switch selector: Copy<SwitchSelector initial={0} onPress={(value) => scrollTo(value)} textColor={'#3E82FF'} //'#7a44cf' selectedColor={'#fff'} buttonColor={'#3E82FF'} borderColor={'#3E82FF'} hasPadding options={[ { label: "User", value: "user"}, { label: "Business", value: "business"} ]} style={{ marginTop: 90, marginLeft: 40, marginRight:40 }} /> Mobile Development Collective · javascript · ios · reactjs ·
🌐
React Native
reactnative.dev › docs › switch
Switch · React Native
2 weeks ago - Re-watch the latest React Native Keynote from React Conf 2025 · On this page · Renders a boolean input. This is a controlled component that requires an onValueChange callback that updates the value prop in order for the component to reflect ...
🌐
npm
npmjs.com › package › react-switch-selector
react-switch-selector - npm
August 6, 2024 - Tiny switch/toggle component for React️ ⚛. Latest version: 2.3.1, last published: 4 months ago. Start using react-switch-selector in your project by running `npm i react-switch-selector`. There are 13 other projects in the npm registry using react-switch-selector.
      » npm install react-switch-selector
    
Published   Jan 02, 2026
Version   2.3.1
🌐
DEV Community
dev.to › musatov › conditional-rendering-in-react-with-a-switch-component-23ph
Conditional Rendering in React with a Switch Component - DEV Community
December 3, 2023 - In summary, the Switch component we've created allows a cleaner and more expressive way to handle conditional rendering in React, similar to a switch-case statement. It filters and renders child components based on the provided condition, providing ...
Find elsewhere
🌐
DEV Community
dev.to › innrvoice › multi-option-switchtoggle-component-for-react-4ef4
Multi-option Switch/Toggle component for React - DEV Community
February 2, 2026 - Required array of options to switch between. Every option is array should have a shape corresponding to CustomSwitcherOption: export type CustomSwitcherOption<OptionValue> = { value: OptionValue; label?: string | React.ReactElement; color?: string; };
🌐
Syncfusion
syncfusion.com › react › toggle switch button
React Toggle Switch Button – Responsive & Customizable | Syncfusion
February 3, 2026 - You can make use of different switch sizes, default and small, as required in your application. The appearance of the React Toggle Switch Button component (bar and handle) can be fully customized. A switch can contain text to represent checked/unchecked states (ON/OFF).
Top answer
1 of 2
1

Unless you are converting an old app to React, i.e. not writing a pure React app from the ground up, don't use ReactDOM.render multiple times. As you want to share the active state between components, it should live in their closest common ancestor.

I'm not sure how your dashboard should work, but here's a demo. Here, APP is such closest ancestor. You don't need react-router if you are not using URL routes or the History API.

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

class Dash extends React.Component {
  render() {
    const { isActive, fctHide, fctShow } = this.props;
    const elements = ["1", "2", "3", "4"];

    const items = [];

    for (const [index, value] of elements.entries()) {
      items.push(
        <button
          key={index}
          onClick={() => {
            fctShow(index);
          }}
        >
          {value}
        </button>
      );
    }

    // if (isActive) {
    return (
      <div>
        <table>
          <tbody>
            <tr>
              <td> {items} </td>
            </tr>
          </tbody>
        </table>
      </div>
    );
    // } else {
    //   return null;
    // }
  }
}

class Prog1 extends React.Component {
  render() {
    const { isActive, selected, fctHide } = this.props;

    if (isActive) {
      return (
        <div className="contProg1">
          <button onClick={fctHide}>Close</button>
          <h1>Program 1</h1>
          <h2>Test1</h2>
          <h2>Test2</h2>
          <h2>Test3</h2>
          Selected: {selected}
          <ul>
            <li>AAAAA</li>
            <li>BBBBB</li>
            <li>CCCCC</li>
          </ul>
        </div>
      );
    } else {
      return null;
    }
  }
}

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = { isActive: true, selected: null };
  }

  fctShow = selected => {
    this.setState({ isActive: true, selected });
  };

  fctHide = () => {
    this.setState({ isActive: false });
  };

  render() {
    const { isActive, selected } = this.state;

    return (
      <>
        <Dash
          isActive={isActive}
          fctHide={this.fctHide}
          fctShow={this.fctShow}
        />
        <Prog1 isActive={isActive} selected={selected} fctHide={this.fctHide} />
      </>
    );
  }
}
2 of 2
0

OK ! I finally use as proposed react-router. But I used the Hooks version (with <A>...)

So, the little dashboard is splitted in X parts :

  • The HTML with only the minimum and root. <div id="root"></div>
  • The CSS (nothing to say more)
  • The sub apps in a specific folder "Apps"
import React from "react";
import { A } from "hookrouter";

class Prog1 extends React.Component {
  render() {
    return (
      <div class="contProg1">
        <button class="close">
          {" "}
          <A href="/">Close</A>
        </button>
        <h1>Program 1</h1>
        <h2>Test1</h2>
        <h2>Test2</h2>
        <h2>Test3</h2>
        <ul>
          <li>AAAAA</li>
          <li>BBBBB</li>
          <li>CCCCC</li>
        </ul>
      </div>
    );
  }
}

export default Prog1;
  • The router page to switch between apps and main Dash.
import React from "react";
import Prog1 from "./Apps/Prog1";
import Prog2 from "./Apps/Prog2";
import Prog3 from "./Apps/Prog3";
import Prog4 from "./Apps/Prog4";
import Dash from "./App";

const routes = {
  "/": () => <Dash />,
  "/Prog1": () => <Prog1 />,
  "/Prog2": () => <Prog2 />,
  "/Prog3": () => <Prog3 />,
  "/Prog4": () => <Prog4 />
};

export default routes;

  • The main page, the Dashboard (App.js).
import React from "react";
import { A } from "hookrouter";

const elements = ["1", "2", "3", "4"];

function Dash() {
  const items = [];

  for (const [index, value] of elements.entries()) {
    items.push(
      <A href={"/Prog" + (index + 1)}>
        <button key={index}>{value}</button>
      </A>
    );
  }

  return (
    <div className="Dash">
      <table>
        <tr>
          <td> {items} </td>
        </tr>
      </table>
    </div>
  );
}

export default Dash;
  • And to finish, the Index page :
import React from "react";
import { render } from "react-dom";
import "./styles.css";
import { useRoutes } from "hookrouter";
import routes from "./router";
import NoPageFound from "./Apps/404";

function App() {
  const routeResult = useRoutes(routes);
  return <div className="Dash">{routeResult || <NoPageFound />}</div>;
}

render(<App />, document.getElementById("root"));

It works well. I just need to add something like MemoryRouter or something else to hide the URL and prepare for mobile version. I'm just a little bit scared when I will insert this part in a Django project. Or, maybe I should separate it ? (You don't need to answer, I will close I think).

Thanks :)

🌐
Stack Overflow
stackoverflow.com › questions › 72119196 › react-switch-selector-error-in-react-18-broken
reactjs - react-switch-selector error in react 18 broken - Stack Overflow
import React from "react"; import SwitchSelector from "react-switch-selector"; const Toggles: React.FC = () => { const options = [ { label: <span>Foo</span>, value: { foo: true, }, selectedBackgroundColor: "#0097e6", }, { label: "Bar", value: "bar", selectedBackgroundColor: "#fbc531", }, ]; const onChange = (newValue: any) => { console.log(newValue); }; const initialSelectedIndex = options.findIndex( ({ value }) => value === "bar" ); return ( <div className="your-required-wrapper" style={{ width: 100, height: 30 }}> <SwitchSelector onChange={onChange} options={options} initialSelectedIndex={initialSelectedIndex} backgroundColor={"#353b48"} fontColor={"#f5f6fa"} /> </div> ); }; export default Toggles;
🌐
SitePoint
sitepoint.com › blog › javascript › create a toggle switch in react as a reusable component
Create a Toggle Switch in React as a Reusable Component — SitePoint
November 15, 2024 - We can start by setting up a basic HTML checkbox input form element for our toggle React component with its necessary properties. ... Then, add an enclosing <div> tag around it and a <label> tag right below the <input> tag to create a label saying, Toggle Me! <div class="toggle-switch"> <input type="checkbox" class="toggle-switch-checkbox" name="toggleSwitch" id="toggleSwitch" /> <label class="toggle-switch-label" for="toggleSwitch"> Toggle Me!
🌐
GitHub
github.com › GR34SE › react-switch-selector › issues
GR34SE/react-switch-selector
Tiny switch/toggle component for React️ ⚛. Contribute to GR34SE/react-switch-selector development by creating an account on GitHub.
Author   GR34SE
🌐
CoreUI
coreui.io › react › documentation › forms › switch
React Switch Components - CoreUI
January 13, 2021 - React Switch Components are a type of UI component that allows users to toggle between two states, usually represented as "on" or "off", "enabled" or "disabled", or "checked" or "unchecked".
🌐
Snyk
security.snyk.io › snyk vulnerability database › npm
react-switch-selector | Snyk
We found that react-switch-selector demonstrates a positive version release cadence with at least one new version released in the past 12 months.
🌐
React
react.dev › reference › react-dom › components › select
<select> – React
A select box cannot switch between being controlled or uncontrolled over its lifetime.
🌐
DEV Community
dev.to › karltaylor › creating-a-switch-toggle-in-react-using-styled-components-1enn
Creating a Switch Toggle in React using styled-components. - DEV Community
December 16, 2021 - ```tsx const Input = styled.input` display: none; &:checked + ${Switch} { background: green; } `; ``` ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/njqr2tvdm8g2nx5wvxw0.jpg) Now in that same nested css structure, we can target the `:before` pseudo-element of the `Switch` element: ```tsx const Input = styled.input` display: none; &:checked + ${Switch} { background: green; &:before { transform: translate(32px, -50%); } } `; ``` ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zrdw74swfzupkpusv889.jpg) Now all we have to do animate this
🌐
CodeSandbox
codesandbox.io › examples › package › react-switch-selector
react-switch-selector examples - CodeSandbox
Use this online react-switch-selector playground to view and fork react-switch-selector example apps and templates on CodeSandbox.