react-count-provider
v1.0.5
Published
A simple React count provider for shared state management.
Downloads
5
Maintainers
Readme
React Count Provider
This is a simple npm package that utilizes React, TypeScript, and Vite. It was created to test shared state management when the state is maintained in an external package.
Installation
To install the React Count Provider package, you can use npm or yarn:
npm install react-count-provider
or
yarn add react-count-provider
Usage
To use the React Count Provider in your React application, follow these steps:
- Import the
CountProvider
component from the package:
import { CountProvider } from 'react-count-provider';
- Wrap your application or component with the
CountProvider
component:
<CountProvider object={someKey: "someValue"}>
{/* Your application or component code here */}
</CountProvider>
- Access the count value and update it using the provided hooks in any of the child components as follows:
import { useCount } from "./CountProvider";
const MyComponent = () => {
const { count, increment, decremen } = useCount();
return (
<div>
<p>Count: {count}</p>
<button onClick={increment}>Increment</button>
<button onClick={decrement}>Decrement</button>
</div>
);
};
That's it! You can now manage and share the count state across your React components using the React Count Provider package.