dgn-contexts
v1.0.13
Published
Redux contexts package for DGN platform
Readme
DGN Contexts Package
A Redux contexts package for the DGN platform containing all state management logic.
Installation
Since this is a local package, you can install it using npm link or by referencing the local path.
Method 1: Using npm link (Recommended)
- In the package directory:
cd /path/to/dgn-contexts-package
npm install
npm run build
npm link- In your Next.js application:
npm link dgn-contextsMethod 2: Using local path in package.json
Add this to your Next.js app's package.json:
{
"dependencies": {
"dgn-contexts": "file:../dgn-contexts-package"
}
}Usage
Basic Setup
import { store, useAppDispatch, useAppSelector } from 'dgn-contexts';
import { Provider } from 'react-redux';
// Wrap your app with the Redux provider
function App() {
return (
<Provider store={store}>
<YourAppComponents />
</Provider>
);
}Using in Components
import { useAppSelector, useAppDispatch } from 'dgn-contexts';
import { useAnnotationsActions, useAnnotationsState } from 'dgn-contexts';
function MyComponent() {
const dispatch = useAppDispatch();
const userState = useAppSelector(state => state.user);
const annotationsState = useAnnotationsState();
const annotationsActions = useAnnotationsActions();
// Use the state and actions as needed
return (
<div>
<p>User: {userState.name}</p>
<button onClick={() => annotationsActions.loadAnnotations()}>
Load Annotations
</button>
</div>
);
}Available Contexts
user- User state managementtriggers- Triggers state managementspecialEvent- Special events state managementannotations- Annotations state managementspeak2earn- Speak2Earn state managementsocket- Socket connection state managementforum- Forum state managementannotation- Single annotation state management
Available Hooks
useAppDispatch()- Get the typed dispatch functionuseAppSelector()- Get the typed selector functionuseAnnotationsState()- Get annotations stateuseAnnotationsActions()- Get annotations actions- And more context-specific hooks...
Development
Building the Package
npm run buildDevelopment Mode
npm run devThis will watch for changes and rebuild automatically.
Cleaning Build Files
npm run cleanDependencies
This package requires the following peer dependencies:
@reduxjs/toolkit^2.0.0react^18.0.0 || ^19.0.0react-redux^8.0.0 || ^9.0.0nexus-react-core^1.0.0
Make sure these are installed in your main application.
