
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
@mindspace-io/react-akita
Advanced tools
Just install
@mindspace-io/react-akita
to use.
A small, super powerful statemanagement library for React... using an Akita engine and Zustand-like API.
This React library now provides super-powered Store createStore()
function to simultaneously
useStore(<selector>)
to easily re-render the view when the state changes.Developers familiar with Vue will recognize this state management approach using stores and mutators:
The beauty of the createStore()
is that a factory function is used to build the initial state.
And the factory function is actually provided the [set
, get
, ...] store api:
import create from '@mindspace-io/react-akita';
// Define store structure
interface StoreState {
bears: number;
increasePopulation: () => void;
removeAllBears: () => void;
}
const onBuildState = ({ set, get }) => {
return {
// Properties
bears: 0,
// Mutators
increasePopulation: () => set((state) => ({ bears: state.bears + 1 })),
removeAllBears: () => set({ bears: 0 }),
// Computed Properties (none here)
// Watch Properties (none here)
};
};
// Build a React hook connected 'live' to the store state
const useStore = createStore<StoreState>(onBuildState);
In fact, the
hook
is both a BOTH a React Hook and a Store API.
Now bind your components to use the state returned by the hook... and that's it!
Use the hook anywhere, no providers needed. Select your state and the component will re-render on state changes.
function BearCounter() {
const bears = useStore((state) => state.bears);
return <h1>{bears} around here ...</h1>;
}
function Controls() {
const increasePopulation = useStore((state) => state.increasePopulation);
return <button onClick={increasePopulation}>one up</button>;
}
You can also use multiple useStore()
hooks - each from different stores.
import { useEmailStore, EmailState } from './email.store';
import { useEmployeeStore, EmployeeState } from './employee.store';
function AuditReport() {
const emails = useEmailStore((state: EmailState) => state.emails);
const people = useEmployeeStore((state: EmployeeState) => state.executives);
return <p>
{people.length} Executives found! <br>
{emails.length} Emails missing.
</p>;
}
You cannot use the same hook multiple times in the same component:
function BearCounter() {
const bears = useBearStore((state) => state.bears);
const increasePopulation = useBearStore((state) => state.increasePopulation);
return <h1>{bears} around here ...</h1>;
}
This ^ will generate runtime errors since the same useStore
reference can only be used once in a view.
The solution is to combine the two (2) selectors into a single, composite selector:
function BearCounter() {
const selector = [(state) => state.bears, (state) => state.increasePopulation];
const [bears, increasePopulation] = useBearStore(selector);
return <h1 onClick={increasePopulation}>{bears} around here ...</h1>;
}
Whenever those two (2) values change, then the view will be re-rendered with the latest values.
The important concept here is that the selector
is used to build a live connection between those properties in the Store state and the View component.
When a store is created, the variable reference also has the following functional API:
export interface StoreApi<T extends State> extends StatusAPI {
set: SetState<T>;
get: GetState<T>;
// Used to batch state changes
applyTransaction: ApplyTransaction<T>;
// Used during store configuration
addComputedProperty: AddComputedProperty<T>;
watchProperty: WatchProperty<T>;
// notifications do NOT trigger UI re-renders
observe: Subscribe<T>;
// Used to announce status
setIsLoading: SetLoading;
setError: SetError;
destroy: Destroy;
}
const store: StoreAPI<StoreState> = createStore<StoreState>(onStoreReady);
Using the Store API allows developers to imperatively query/update state, subscribe for change notifications, or dispose of the store.
This can be very useful for scenarios where the API is used outside a Component; the React Hook may not be available.
Often state management requires status tracking for loading activity and error conditions.
error
+ isLoading
setIsLoading()
+ setError()
In addition to standard Store API, the store is also auto enhanced with the following features:
export interface StatusAPI {
setIsLoading: (isLoading = true) => void;
setError: (error: unknown) => void;
}
export type Status = { isLoading: boolean; error: unknown };
A CodeSandbox demo has been prepared to allow developers to quickly and easily play with these features:
Just install with:
npm install @mindspace-io/react-akita
Under the hood, this library uses immer
, @datorama/akita
, and rxjs
; these will be automatically installed along with @mindspace-io/react-akita
.
FAQs
React hooks + utilities for Akita State Management
We found that @mindspace-io/react-akita 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.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.