I'm trying to use a hook in React. The hook should give me a boolean and a callback. When the callback gets called the boolean should change value. When I try to retrieve the value and the callback I get an error.
Property
isEnableddoes not exist on type(boolean | (() => void))[]. On the lineconst {isEnabled, toggleCallback} = useToggle();
What am I doing wrong?
function toggleCallback(toggleCallback: () => void) {
toggleCallback();
}
export default function FakePage(props: any) {
const {isEnabled, toggleCallback} = useToggle();
return (
<div>
<ComponentOne isEnabled={isEnabled}/>
<button onClick={() => testToggle(toggleCallback)}>Test</button>
</div>
);
}
// hook
export default function useToggle() {
let isEnabled: boolean = true;
const toggleCallback= useCallback(() => {
isEnabled = !isEnabled;
}, [isEnabled]);
return [isEnabled, toggleCallback];
}