Skip to content

useStore

Accesses the global state within the Midl context. Under the hood, it uses zustand's useStore hook.

Import

ts
import { useStore } from '@midl/react';

Example

tsx
const store = useStore();
// or with a custom store
const store = useStore(customStore);

Parameters

NameTypeDescription
customStoreMidlContextStore(optional) Custom Zustand store instance to use instead of context.

Returns

TypeDescription
StoreThe Zustand store instance for the current context (or the provided custom store).

Extending MIDL Context interface

You can extend the MIDL context interface to include your own state.

ts
declare module "@midl/react" {
	type State = {
        user: {
            address: string;
        };
	};

	export interface MidlContextState extends State {}
}