another controlled state hook
npm install ucs
import React from "react";
import useControlledState from "ucs";
const Toggler = ({ value, onChange, defaultValue }) => {
const [state, setState] = useControlledState(() => value || defaultValue);
return (
<button onClick={() => setState(!state)}>{state ? "on" : "off"}</button>
);
};
see demo and example of usage on gh-pages
MIT © jeetiss