Currently I have a toggle switch from the Semantic UI React library and I am setting the checked property to be defaulted to false on the page.
I want to make it toggable so the user can click on it but I need to add a OnClick event property. I want to create a function to handle this but I don't want to use state hooks which were introduced in React.JS version 16 and am not sure how to go about it.
Here is my ToggleSwitch.tsx file where I create the toggle switch
import * as React from "react";
import { Checkbox } from 'semantic-ui-react'
import * as PropTypes from "prop-types";
const ToggleSwitch = ({ id, name,label, checked, onclick }) => {
return (
<Checkbox
name={name}
id={id}
label={label}
checked={checked}
onclick={onclick}
toggle
/>
);
}
ToggleSwitch.propTypes = {
id: PropTypes.string.isRequired,
checked: PropTypes.bool.isRequired,
label: PropTypes.string,
name: PropTypes.string,
onclick: PropTypes.func,
};
export default ToggleSwitch;
I then insert the switch into my subheader.tsx which creates a subheader across multiple pages on my website which now will have this switch
import * as React from "react";
import ToggleSwitch from './new_layout/ToggleSwitch'
interface Props {
name: string;
renderAction?: () => any;
}
const SubHeader: React.SFC<Props> = ({ name, renderAction }) => {
return (
<div className="settings-submenu">
<div className="settings-submenu-name">{name}</div>
<div className="settings-submenu-name">{renderAction && renderAction()}</div>
<ToggleSwitch name='LayoutToggleSwitch' label='Enable New Layout' id='LayoutToggleSwitch' checked={false} onclick = {} />
</div>
);
};
export default SubHeader;
I am not sure what to put in my OnClick function to make this switch able to be switched as currently when I click on it, it does not change from its checked value which is false