
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
@context-action/react
Advanced tools
React integration for @context-action/core - Context and hooks for type-safe action management
React integration for the Context-Action framework - providing React hooks, components, and patterns for type-safe action management and state isolation.
npm install @context-action/react @context-action/core
# or
pnpm add @context-action/react @context-action/core
import {
createStoreContext,
createActionContext,
useStoreValue,
ActionPayloadMap
} from '@context-action/react';
// 1. Define your actions
interface AppActions extends ActionPayloadMap {
updateUser: { name: string; email: string };
resetUser: void;
}
// 2. Create Action Context
const {
Provider: UserActionProvider,
useActionDispatch,
useActionHandler
} = createActionContext<AppActions>('UserActions');
// 3. Create Store Pattern
const {
Provider: UserStoreProvider,
useStore: useUserStore,
withProvider
} = createStoreContext('User', {
profile: { initialValue: { name: 'John Doe', email: 'john@example.com' } }
});
// 4. Create component with automatic providers
const UserProfile = withProvider(() => {
const dispatch = useActionDispatch();
const profileStore = useUserStore('profile');
const user = useStoreValue(profileStore);
// Register action handler
useActionHandler('updateUser', async (payload) => {
profileStore.setValue(payload);
});
const handleUpdate = () => {
dispatch('updateUser', {
name: 'Updated User',
email: 'updated@example.com'
});
};
return (
<div>
<h1>Welcome, {user.name}!</h1>
<p>Email: {user.email}</p>
<button onClick={handleUpdate}>Update Profile</button>
</div>
);
});
// 5. Use with combined providers
function App() {
return (
<UserActionProvider>
<UserStoreProvider>
<UserProfile />
</UserStoreProvider>
</UserActionProvider>
);
}
Create type-safe stores with excellent inference:
const AppStores = createStoreContext('App', {
user: { initialValue: { id: '', name: '' } },
settings: { initialValue: { theme: 'light' } },
data: { initialValue: [] }
});
function MyComponent() {
const userStore = AppStores.useStore('user'); // Fully typed
const settingsStore = AppStores.useStore('settings');
const user = useStoreValue(userStore);
const settings = useStoreValue(settingsStore);
return <div>User: {user.name}, Theme: {settings.theme}</div>;
}
// Automatic provider wrapping
const MyComponentWithProvider = AppStores.withProvider(MyComponent);
Centralized action management with type safety:
interface UserActions extends ActionPayloadMap {
login: { username: string; password: string };
logout: void;
updateProfile: { name: string; email: string };
}
const UserActions = createActionContext<UserActions>('UserActions');
function LoginComponent() {
const dispatch = UserActions.useActionDispatch();
// Register handlers with priorities
UserActions.useActionHandler('login', async (payload) => {
const response = await api.login(payload);
// Handle login logic
}, { priority: 10 });
UserActions.useActionHandler('login', async (payload) => {
analytics.track('login_attempt');
}, { priority: 5 });
const handleLogin = () => {
dispatch('login', { username: 'user', password: 'pass' });
};
return <button onClick={handleLogin}>Login</button>;
}
Selective subscriptions and computed values:
function OptimizedComponent() {
const userStore = useUserStore('profile');
// Subscribe to specific field only
const userName = useStoreSelector(userStore, user => user.name);
// Computed values that auto-update
const displayName = useComputedStore(
userStore,
user => user.nickname || user.name || 'Anonymous'
);
// Component-local store
const { value: localCount, setValue } = useLocalStore(0);
return (
<div>
<p>Name: {userName}</p>
<p>Display: {displayName}</p>
<p>Local: {localCount}</p>
<button onClick={() => setValue(prev => prev + 1)}>
Increment Local
</button>
</div>
);
}
createActionContext<T>() - Creates type-safe action systemcreateStoreContext() - Creates type-safe store managementuseStoreValue(store) - Subscribe to store changesuseActionDispatch() - Dispatch actions to handlersuseActionHandler() - Register action handlersuseStore() - Access stores by name (from pattern)useStoreSelector(store, selector) - Selective subscriptionsuseComputedStore(store, compute) - Derived stateuseLocalStore(initialValue) - Component-local storeuseActionDispatchWithResult() - Collect handler resultsassertStoreValue(value, storeName) - Runtime type assertionshallowEqual(a, b) - Shallow object comparisondeepEqual(a, b) - Deep object comparisonEach pattern instance provides complete isolation:
// Independent store contexts
const FeatureAStores = createStoreContext('FeatureA', {
data: { initialValue: [] }
});
const FeatureBStores = createStoreContext('FeatureB', {
data: { initialValue: [] }
});
// Components operate independently
const FeatureA = FeatureAStores.withProvider(MyComponent);
const FeatureB = FeatureBStores.withProvider(MyComponent);
// Automatic provider wrapping
const UserComponent = UserStores.withProvider(() => {
const userStore = UserStores.useStore('profile');
const user = useStoreValue(userStore);
return <div>{user.name}</div>;
});
// No manual provider wrapping needed!
function App() {
return <UserComponent />;
}
function DataComponent() {
const dispatch = useActionDispatch();
// Validation (highest priority)
useActionHandler('saveData', async (payload) => {
if (!payload.id) throw new Error('ID required');
}, { priority: 10 });
// Main logic
useActionHandler('saveData', async (payload) => {
await api.saveData(payload);
}, { priority: 5 });
// Analytics (lowest priority)
useActionHandler('saveData', async (payload) => {
analytics.track('data_saved');
}, { priority: 1 });
return <button onClick={() => dispatch('saveData', { id: '1' })}>
Save
</button>;
}
// Before
const userStore = createStore('user', { name: '' });
function UserComponent() {
const user = useStoreValue(userStore);
return <div>{user.name}</div>;
}
// After (Declarative Store Pattern)
const UserStores = createStoreContext('User', {
profile: { initialValue: { name: '' } }
});
const UserComponent = UserStores.withProvider(() => {
const profileStore = UserStores.useStore('profile');
const user = useStoreValue(profileStore);
return <div>{user.name}</div>;
});
useActionHandler with useCallbackAll essential hooks are thoroughly tested with 40+ passing tests:
# Run tests
pnpm test
# Core hooks tested:
# - useStoreValue (4 tests)
# - useLocalStore (4 tests)
# - createActionContext (8 tests)
# - useActionDispatch (6 tests)
# - useComputedStore (5 tests)
# - Comparison utilities (13 tests)
Optimized bundle size after cleanup:
The Context-Action framework follows MVVM principles:
Full type safety with excellent inference:
// Excellent type inference
const UserStores = createStoreContext('User', {
profile: { initialValue: { id: '', name: '' } }
});
// userStore is fully typed as Store<{id: string, name: string}>
const userStore = UserStores.useStore('profile');
// Actions are type-checked
interface MyActions extends ActionPayloadMap {
updateUser: { id: string; name: string };
deleteUser: { id: string };
}
const dispatch = useActionDispatch<MyActions>();
dispatch('updateUser', { id: '1', name: 'John' }); // ✅ Type safe
dispatch('updateUser', { wrong: 'data' }); // ❌ Type error
Apache-2.0 - see LICENSE for details.
FAQs
React integration for @context-action/core - Context and hooks for type-safe action management
We found that @context-action/react demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.