
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
orpheus-bind
Advanced tools
OrpheusBind is a simple, lightweight, and type-safe global state management library for React applications. It leverages the power of React hooks and RxJS to provide an easy-to-use solution for managing your application state.
OrpheusBind is a simple, lightweight, and type-safe global state management library for React applications. It leverages the power of React hooks and RxJS to provide an easy-to-use solution for managing your application state.
Add OrpheusBind to your project with the following command:
npm install orpheus-bind
or
yarn add orpheus-bind
Create a file to define your custom global state hook, including the state interface and initial state:
// src/userGlobalState.ts
import { createGlobalState, Middleware } from 'orpheus-bind';
export interface UserGlobalState {
user: {
id: number;
name: string;
} | null;
}
const initialState: UserGlobalState = {
user: null,
};
// Optional middleware for logging state updates
const middleware: Middleware<UserGlobalState> = (currentState, newState) => {
console.log('Updating state:', currentState, newState);
return newState;
};
export const useUserGlobalState = createGlobalState<UserGlobalState>({ initialState, middleware });
Utilize your custom global state hook in any component:
// src/SomeComponent.tsx
import React from 'react';
import { useUserGlobalState } from './userGlobalState';
const SomeComponent: React.FC = () => {
const [state, updateState] = useUserGlobalState();
const handleLogin = () => {
updateState({ user: { id: 1, name: 'John Doe' } });
};
const handleLogout = () => {
updateState({ user: null });
};
return (
<div>
{state.user ? (
<>
<div>Welcome, {state.user.name}!</div>
<button onClick={handleLogout}>Logout</button>
</>
) : (
<button onClick={handleLogin}>Login</button>
)}
</div>
);
};
export default SomeComponent;
OrpheusBind provides a convenient resetState
method that allows you to reset the global state back to its initial value. This is useful when you want to clear the current state and start from scratch.
Create a file to define your custom global state hook, including the state interface and initial state:
// src/SomeComponent.tsx
import React from 'react';
import { useUserGlobalState } from './userGlobalState';
const SomeComponent: React.FC = () => {
const [state, updateState, resetState] = useUserGlobalState();
const handleLogin = () => {
updateState({ user: { id: 1, name: 'John Doe' } });
};
const handleLogout = () => {
resetState();
};
return (
<div>
{state.user ? (
<>
<div>Welcome, {state.user.name}!</div>
<button onClick={handleLogout}>Logout</button>
</>
) : (
<button onClick={handleLogin}>Login</button>
)}
</div>
);
};
export default SomeComponent;
FAQs
OrpheusBind is a simple, lightweight, and type-safe global state management library for React applications. It leverages the power of React hooks and RxJS to provide an easy-to-use solution for managing your application state.
The npm package orpheus-bind receives a total of 2 weekly downloads. As such, orpheus-bind popularity was classified as not popular.
We found that orpheus-bind demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.