question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

consider using Immer

See original GitHub issue

People get immutability wrong all the time (self included). Even the ones that know what they’re doing often have to write some really messy code when deep state updates are involved.

Immer seems to achieve the best of both worlds. We should consider bundling it in (and possible have a flag that allows turning it off for people that prefer not to use it).

move: (G, ctx) {
  G.hand++;
  G.deck--;
}

vs.

move: (G, ctx) {
  return {
    ...G,
    hand: G.hand + 1,
    deck: G.deck - 1,
  };
}

Open questions:

  1. How do we indicate invalid moves ( #292 ) in this approach?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
nicolodaviscommented, Nov 27, 2018

Supported in 0.28.0.

0reactions
philihpcommented, Nov 8, 2018

I can see the advantage of having current code errantly mutating state being safe once this is implemented. Immer automatically binds this to the draft of G inside of produce, so I would expect both should work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Immer with React: a Simple Solutions for Immutable ...
Based on my experience with Immer, I believe it is a great option to use with React. It will simplify your code and...
Read more >
Using TypeScript or Flow | Immer - GitHub Pages
The Immer package ships with type definitions inside the package, which should be picked up by TypeScript and Flow out of the box...
Read more >
Better Reducers With Immer - Smashing Magazine
In this article, we're going to learn how to use Immer to write reducers. When working with React, we maintain a lot of...
Read more >
Immutability in React with Immer - LogRocket Blog
To better deal with state data, a library was created to help us, called Immer. Immer was created to help us to have...
Read more >
Writing Reducers with Immer | Redux Toolkit - JS.ORG
Our answer is always the same: Immer is required in RTK, and that is not going to change. It's worth going over the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found