import { useState } from 'react'; import { createHook } from 'hookleton'; // useCounter is a useState but global const useCounter = createHook(useState); const Increment = () => { const [, update] = useCounter(); const increment = () => update(s => s + 1); return ; }; const Decrement = () => { const [, update] = useCounter(); const decrement = () => update(s => s - 1); return ; }; // The host component const Value = () => { const [count] = useCounter.use(0); return {count}; }; // Value componet must be at the top export default () => (
);