Aller au contenu principal

stubObject()

stubObject(): object

Returns an empty object.

DEPRECATED

Use an inline arrow function () => ({}) instead.


Returns: object​

An empty object.


Since​

2.0.0


Also known as​

stubObject (Lodash, es-toolkit) · ❌ (Remeda, Radashi, Ramda, Effect, Modern Dash, Antfu)


Example​

// ❌ Deprecated approach
stubObject(); // => {}

// ✅ Recommended approach
(() => ({}))(); // => {}

How it works?​

Returns an empty object. Deprecated: Use () => ({}) directly.

Native Equivalent​

// ❌ stubObject
// ✅ () => ({})

Use Cases​

Return empty object 📌​

Return empty object as default.

const getDefaults = () => ({});

Initialize state​

Create empty initial state.

const createState = () => ({});
const state = createState();