Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Redux Toolkit · Function

createSelectorCreator

Creates a customized createSelector factory by choosing the memoization function used for selector result functions. It accepts either a memoizer with optional configuration arguments or an options object.

Since
5.0.0 for the options-object form

How it works

createSelectorCreator builds a customized createSelector function by configuring the memoizer used for each selector's result function. Pass a memoization function directly, optionally followed by its configuration values, or pass an options object with memoize and related settings. The returned creator accepts normal createSelector inputs and returns memoized selectors.

Syntax

createSelectorCreator(memoize, ...memoizeOptions)
createSelectorCreator(options)

Parameters

NameTypeDescription
memoizeMemoizeFunctionMemoization function used for the result function, such as lruMemoize or weakMapMemoize; this is also supplied through the options-object form.
...memoizeOptionsunknown[]Optional configuration values forwarded to the memoization function after the result function.
optionsCreateSelectorOptionsObject form introduced in Reselect 5.0.0; it contains memoize and optional memoization configuration.

Returns

A customized createSelector function.

Key points

  • It returns a selector factory whose behavior is customized independently from the standard createSelector export.
  • Each generated selector's result function is handed to the configured memoizer as its first input.
  • In positional usage, every value after the memoizer is forwarded to that memoizer after the result function.
  • The return value is not a selector for state; it is a function used to construct selectors.

Common mistakes

  • Using this API changes the memoizer from the default weakMapMemoize; choose a replacement deliberately.
  • The positional form accepts zero or more memoizer options, so their meaning depends on the selected memoization function.
  • The object-based form is available from Reselect 5.0.0 onward; older supported usage may require positional arguments.

Example: Create a selector with custom memoization

import { createSelectorCreator, lruMemoize } from '@reduxjs/toolkit'

type State = { todos: { id: number; done: boolean }[] }

const createAppSelector = createSelectorCreator(lruMemoize)
const selectCompletedCount = createAppSelector(
  [(state: State) => state.todos],
  (todos) => todos.filter((todo) => todo.done).length,
)

const state: State = { todos: [{ id: 1, done: true }, { id: 2, done: false }] }
console.log(selectCompletedCount(state))

Creates a selector factory using LRU memoization, then uses it to derive the number of completed todos.

When to use it

Choose a different memoizer

You need selector result memoization behavior different from the default configured memoizer.

Forward memoizer options

A memoizer exposes tuning values such as cache-related settings.

Customize RTK Query selectors

An RTK Query API should use a custom selector creator across its modules.

Interview questions

QWhat does createSelectorCreator do?

It creates a customized version of createSelector. The customization primarily replaces the memoization function used for the selector result function, and the returned value is itself a selector creator.

Follow-up: How can it receive memoizer configuration? Use the rest parameters after the memoizer, or provide an options object containing memoize and additional settings.

QWhat is the role of the memoize argument?

The first argument is the memoization function responsible for memoizing the resultFunc. Common choices documented for this API include lruMemoize and weakMapMemoize.

Follow-up: What happens when no memoizer is explicitly provided in the relevant memoization configuration? The documentation says weakMapMemoize is used.

QWhat invocation forms are supported?

The creator supports a positional form with memoize followed by ...memoizeOptions, and an options-object form containing memoize. The object form was added in version 5.0.0.

Follow-up: Why use a custom creator in RTK Query? Supply the resulting selector creator through the API-building modules when custom selector memoization is needed.

  • createSelector
  • createDraftSafeSelectorCreator
  • lruMemoize
  • weakMapMemoize

Source: createSelectorCreator | Redux. Checked 2026-10-15.