oleng-common-utils
v0.0.4
Published
Utility for various common functions
Readme
oleng-common-utils
Installation
To install the package, run:
npm install oleng-common-utilsUsage
Using GenericContext and GenericProvider
- Import
GenericProvideranduseGenericContextin your React component.
import React from 'react';
import { GenericProvider, useGenericContext } from 'oleng-common-utils';- Wrap your component tree with
GenericProviderand provide an initial state.
const initialState = { key: 'value' };
function App() {
return (
<GenericProvider initialState={initialState}>
<YourComponent />
</GenericProvider>
);
}- Use
useGenericContextto access and update the state within your components.
function YourComponent() {
const { state, setState } = useGenericContext();
const updateState = () => {
setState({ ...state, key: 'newValue' });
};
return (
<div>
<p>{state.key}</p>
<button onClick={updateState}>Update State</button>
</div>
);
}