Function immutablyReduce

  • The produce function takes a value and a "recipe function" (whose return value often depends on the base state). The recipe function is free to mutate its first argument however it wants. All mutations are only ever applied to a copy of the base state.

    Pass only a function to create a "curried producer" which relieves you from passing the recipe function every time.

    Only plain objects and arrays are made mutable. All other objects are considered uncopyable.

    Note: This function is bound to its Immer instance.

    Type Parameters

    • Curried

    Parameters

    • recipe: InferRecipeFromCurried<Curried>
    • Optional initialState: InferInitialStateFromCurried<Curried>

    Returns Curried

    a new state, or the initial state if nothing was modified

  • The produce function takes a value and a "recipe function" (whose return value often depends on the base state). The recipe function is free to mutate its first argument however it wants. All mutations are only ever applied to a copy of the base state.

    Pass only a function to create a "curried producer" which relieves you from passing the recipe function every time.

    Only plain objects and arrays are made mutable. All other objects are considered uncopyable.

    Note: This function is bound to its Immer instance.

    Type Parameters

    • Recipe extends AnyFunc

    Parameters

    Returns InferCurriedFromRecipe<Recipe, false>

    a new state, or the initial state if nothing was modified

  • The produce function takes a value and a "recipe function" (whose return value often depends on the base state). The recipe function is free to mutate its first argument however it wants. All mutations are only ever applied to a copy of the base state.

    Pass only a function to create a "curried producer" which relieves you from passing the recipe function every time.

    Only plain objects and arrays are made mutable. All other objects are considered uncopyable.

    Note: This function is bound to its Immer instance.

    Type Parameters

    • State

    Parameters

    • recipe: ((state, initialState) => ValidRecipeReturnType<State>)
        • (state, initialState): ValidRecipeReturnType<State>
        • Parameters

          Returns ValidRecipeReturnType<State>

    Returns ((state?) => State)

    a new state, or the initial state if nothing was modified

  • The produce function takes a value and a "recipe function" (whose return value often depends on the base state). The recipe function is free to mutate its first argument however it wants. All mutations are only ever applied to a copy of the base state.

    Pass only a function to create a "curried producer" which relieves you from passing the recipe function every time.

    Only plain objects and arrays are made mutable. All other objects are considered uncopyable.

    Note: This function is bound to its Immer instance.

    Type Parameters

    • State
    • Args extends any[]

    Parameters

    • recipe: ((state, ...args) => ValidRecipeReturnType<State>)
        • (state, ...args): ValidRecipeReturnType<State>
        • Parameters

          Returns ValidRecipeReturnType<State>

    • initialState: State

    Returns ((state?, ...args) => State)

    a new state, or the initial state if nothing was modified

  • The produce function takes a value and a "recipe function" (whose return value often depends on the base state). The recipe function is free to mutate its first argument however it wants. All mutations are only ever applied to a copy of the base state.

    Pass only a function to create a "curried producer" which relieves you from passing the recipe function every time.

    Only plain objects and arrays are made mutable. All other objects are considered uncopyable.

    Note: This function is bound to its Immer instance.

    Type Parameters

    • State

    Parameters

    • recipe: ((state) => ValidRecipeReturnType<State>)
        • (state): ValidRecipeReturnType<State>
        • Parameters

          Returns ValidRecipeReturnType<State>

    Returns ((state) => State)

    a new state, or the initial state if nothing was modified

  • The produce function takes a value and a "recipe function" (whose return value often depends on the base state). The recipe function is free to mutate its first argument however it wants. All mutations are only ever applied to a copy of the base state.

    Pass only a function to create a "curried producer" which relieves you from passing the recipe function every time.

    Only plain objects and arrays are made mutable. All other objects are considered uncopyable.

    Note: This function is bound to its Immer instance.

    Type Parameters

    • State
    • Args extends any[]

    Parameters

    • recipe: ((state, ...args) => ValidRecipeReturnType<State>)
        • (state, ...args): ValidRecipeReturnType<State>
        • Parameters

          Returns ValidRecipeReturnType<State>

    Returns ((state, ...args) => State)

    a new state, or the initial state if nothing was modified

  • The produce function takes a value and a "recipe function" (whose return value often depends on the base state). The recipe function is free to mutate its first argument however it wants. All mutations are only ever applied to a copy of the base state.

    Pass only a function to create a "curried producer" which relieves you from passing the recipe function every time.

    Only plain objects and arrays are made mutable. All other objects are considered uncopyable.

    Note: This function is bound to its Immer instance.

    Type Parameters

    • State
    • Recipe extends Function

    Parameters

    Returns InferCurriedFromInitialStateAndRecipe<State, Recipe, false>

    a new state, or the initial state if nothing was modified

  • The produce function takes a value and a "recipe function" (whose return value often depends on the base state). The recipe function is free to mutate its first argument however it wants. All mutations are only ever applied to a copy of the base state.

    Pass only a function to create a "curried producer" which relieves you from passing the recipe function every time.

    Only plain objects and arrays are made mutable. All other objects are considered uncopyable.

    Note: This function is bound to its Immer instance.

    Type Parameters

    Parameters

    • base: Base

      the initial state

    • recipe: ((draft) => ValidRecipeReturnType<D>)
        • (draft): ValidRecipeReturnType<D>
        • Parameters

          • draft: D

          Returns ValidRecipeReturnType<D>

    • Optional listener: PatchListener

    Returns Base

    a new state, or the initial state if nothing was modified