material ui switch code example

Example 1: material-ui switch

import React from "react";
import Switch from "@material-ui/core/Switch";

export default function MaterialuiSwitch() {

  const [state, setState] = React.useState(false);

  function handleSwitchChange (e) {
    setState(e.target.checked);
    // Add actions here for when the switch is triggered
  };

  var text;

  if (state) {
    text = 'on';
  } else {
    text = 'off';
  };

  return (
    <div>
      {text}
      <Switch
        checked={state}
        onChange={handleSwitchChange}
        color="primary"
      />
    </div>
  );
};

Example 2: import switch material ui

import Switch from '@material-ui/core/Switch';

Example 3: Switch Button in react

> npm i bootstrap-switch-button-react --save

import BootstrapSwitchButton from 'bootstrap-switch-button-react'

<BootstrapSwitchButton 
      				onlabel='Hide'
                    onstyle='danger'
                    offlabel='Show'
                    offstyle='success'
					style="border"
                    width={80}
                    onChange={() => {
                        handleReload()
                    }} />
                    <label> Show Hide Switch Button </label>