immerjs / immer

Create the next immutable state by mutating the current one

Home Page:https://immerjs.github.io/immer/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can using immer in this way cause performance issues?

LositoVito opened this issue Β· comments

πŸ™‹β€β™‚ Question

I'm using the last Immer version with React and I've a special situation in which i need to have a class as state. This class contains the actual model and some method to modify it. So it works like a "proxy" for the actual state that is not directly accessible outside the class.

My app is big, but I've made a little fully working CodeSandbox example to show you how i need to use Immer.

It works perfectly, but, as the title says, using Immer in this way is safe and correct or it can cause performance issues?

Thank you for your attention,
Regards,
VL

Well, that depends on whether you want to be able to update 1 or 1 million instances in 10ms. In general, determine your requirements, then measure? Unless proven otherwise, it's gonna be fast enough, and it is quite unlikely that Immer is going to be your performance bottleneck in contrast to for example rendering.