import switch material ui

JavaScript
import Switch from '@material-ui/core/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>
  );
};
Source

Also in JavaScript: