contextover
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

ContextOver - a simple context provider

  • based on React Context & jamiebuilds/unstated-next

  • offers a context over a hook contained logic & values

Install

npm install --save contextover

Example

Create context over hook

const useCount = ({ initialCount }) => {
  const [count, setCount] = useState(initialCount);

  const incrementCount = () => setCount((currentCount) => currentCount + 1);

  return { count, incrementCount };
};

const useCountContext = createContextOver(useCount);

Provide & Consume context

const Counter = () => {
  const { count, incrementCount } = useCountContext.useContext(initialCount);

  return <div onClick={incrementCount}>Count: {count}</div>;
};

const App = () => (
  <useCountContext.ProvideContext initialCount={0}>
    <Counter initialCount={0} />
  </useCountContext.ProvideContext>
);

Readme

Keywords

Package Sidebar

Install

npm i contextover

Weekly Downloads

1

Version

2.0.1

License

MIT

Unpacked Size

10.2 kB

Total Files

8

Last publish

Collaborators

  • negrudev