Rxova
Skip to content

createNamespace

function createNamespace(namespace): ReactNamespace;

Namespaced hooks and factories, so two independently deployed apps on one origin cannot collide by both taking the defaults.

checkout/bus.ts
export const checkout = createNamespace('checkout');
// anywhere in the checkout app
const [items, setItems] = checkout.useSharedState('items', []);

Call it at module scope, like defineStore and defineChannel. It builds a small object of bound functions, and rebuilding that on every render would hand React a new useSharedState identity each time — harmless for the hooks themselves, which key off the bus name, but pointless work and a confusing thing to see in a profile.

See the core createNamespace for what a namespace does and does not guarantee. In short: it prevents collision, not access.

ParameterType
namespacestring

ReactNamespace