Try this, which is way cleaner too: Get that switch out of the render in a function and just call it passing the params you want. For example:

renderSwitch(param) {
  switch(param) {
    case 'foo':
      return 'bar';
    default:
      return 'foo';
  }
}

render() {
  return (
    <div>
      <div>
          // removed for brevity
      </div>
      {this.renderSwitch(param)}
      <div>
          // removed for brevity
      </div>
    </div>
  );
}
Answer from Kelvin De Moya on Stack Overflow
🌐
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-switch
react-switch - npm
December 14, 2024 - A draggable toggle-switch component for React.
      » npm install react-switch
    
Published   Dec 14, 2024
Version   7.1.0
🌐
GitHub
github.com › react-component › switch
GitHub - react-component/switch: React Switch · GitHub
Switch ui component for react.
Starred by 194 users
Forked by 78 users
Languages   JavaScript 45.6% | TypeScript 34.0% | Less 19.8% | Shell 0.6%
🌐
DEV Community
dev.to › promathieuthiry › creating-a-smooth-toggle-switch-in-react-a-step-by-step-guide-3hj
Creating a Smooth Toggle Switch in React: A Step-by-Step Guide - DEV Community
July 15, 2024 - We're going to create a toggle switch that allows users to switch between gallery and list views. The switch will have a smooth sliding animation and change colors to indicate the active state.
Find elsewhere
🌐
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 user actions. If the value prop is not updated, the component will continue to render the supplied value prop instead of the expected result of any user actions. Inherits View Props. If true the user won't be able to toggle the switch.
🌐
Reddit
reddit.com › r/reactjs › build a react switch toggle component
r/reactjs on Reddit: Build a React Switch Toggle Component
July 21, 2019 - IDs especially, because as it stands right now, you'd only be able to use one of these Switch components per page. ... just wanted to express my appreciation for this tutorial. It was very easy to follow and I really appreciated its simplicity. Very well written! ... Now please build an async autocomplete and begin hating the job. ... I've built a complete Window Management library for React!
🌐
Radix UI
radix-ui.com › primitives › docs › components › switch
Switch – Radix Primitives
Switch · Tabs · Toast · Toggle · Toggle Group · Toolbar · Tooltip · Accessible Icon · Direction Provider · Portal · Slot · Visually Hidden · Components · A control that allows the user to toggle between checked and not checked. ...
🌐
Syncfusion
ej2.syncfusion.com › react › documentation › switch › getting-started
Getting started with React Switch component | Syncfusion
February 3, 2026 - This section explains the steps required to create a simple React Switch component and demonstrate its basic usage in a React environment.
🌐
CodeSandbox
codesandbox.io › examples › package › react-triple-toggle-switch
react-triple-toggle-switch examples - CodeSandbox
Use this online react-triple-toggle-switch playground to view and fork react-triple-toggle-switch example apps and templates on CodeSandbox.
🌐
StackBlitz
stackblitz.com › edit › switch-react-component
Switch React Component - StackBlitz
Starter project for React apps that exports to the create-react-app CLI.
🌐
GeeksforGeeks
geeksforgeeks.org › react native › react-native-switch-api
React Native Switch API - GeeksforGeeks
February 16, 2026 - The React Native Switch API is a core component used to toggle between two states, typically on and off.
🌐
Medium
medium.com › nerd-for-tech › a-case-to-switch-using-switch-statements-in-react-e83e01154f60
A Case to Switch. Using Switch Statements in React. | by Michael Sutton | Nerd For Tech | Medium
July 22, 2021 - Secondly, if I’m incorporating 4 components within a logical block of if (state.value === 'value1') else if (state.value === 'value2') else if (state.value === 'value3') else … This starts to become clunky and somewhat difficult to follow. As with vanilla JavaScript within a React App, you can incorporate a Switch Statement to clean up your code.
🌐
Markusenglund
markusenglund.github.io › react-switch
React Switch examples
A draggable, customizable and accessible switch-component for React.
🌐
MUI
v6.mui.com › base-ui › react-switch
React Switch component and hook - MUI Base
The Switch component provides users with a switch for toggling between two mutually exclusive states.
🌐
Adobe
react-aria.adobe.com › Switch
Switch | React Aria
import {Switch} from './Switch'; import {useState} from 'react'; function Example(props) { let [selected, setSelection] = useState(false); return ( <> <Switch {...props}
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › how-to-use-switch-statement-inside-a-react-component
How to use Switch Statement Inside a React Component? - GeeksforGeeks
July 23, 2025 - Using a switch statement in React components improves readability, maintainability, and organization. It provides a more structured and efficient way to handle multiple conditions by avoiding the complexity of multiple if-else statements.
🌐
StackBlitz
stackblitz.com › edit › react-switch-button
React Switch Button - StackBlitz
Starter project for React apps that exports to the create-react-app CLI.
🌐
shadcn/ui
ui.shadcn.com › docs › components › radix › switch
Switch - shadcn/ui
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field" import { Switch } from "@/components/ui/switch" View Code · To enable RTL support in shadcn/ui, see the RTL configuration guide. Arabic (العربية)Toggle · المشاركة عبر الأجهزة · يتم مشاركة التركيز عبر الأجهزة، ويتم إيقاف تشغيله عند مغادرة التطبيق. Copy · "use client" import * as React from "react" View Code ·