use-immer icon indicating copy to clipboard operation
use-immer copied to clipboard

Wrong type for `DraftFunction`?

Open musjj opened this issue 1 year ago • 2 comments

https://github.com/immerjs/use-immer/blob/d0a2daa15a7cdc352990c52fe0fb5dfc5674a5f0/src/index.ts#L4

It currently specifies void as the return type, but you can actually return a new object, like:

const [state, updateState] = useImmer({ some: "value" });
updateState(() => ({ new: "value" }));

From my observations, it's equivalent to:

updateState({ new: "value" });

I was trying to make a wrapper for the updater function and the wrong function signature tripped me up.

musjj avatar Jul 20 '24 12:07 musjj

Correct, encountering the same issue.

simonlsk avatar Sep 15 '24 15:09 simonlsk

PR welcome

mweststrate avatar Sep 27 '24 17:09 mweststrate