2.0.1 • Published 2 years ago

contextover v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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>
);
2.0.1

2 years ago

2.0.0

2 years ago

1.1.0

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago