Imperative attack on react design: immerjs produceWithPatches
See original GitHub issueImmerjs becomes popular tool for react these days. It includes special function named produceWithPatches
. This function can force react component to use imperative design only.
const state = { a: 1, b: 2 }
const [nextState, patches] = produceWithPatches(state, (draft) => {
draft.b = 3
})
Steps To Reproduce
- Use
produceWithPatches
and passnextState
asprop
andpatches
aspropPatches
into component. - Component uses only initial
prop
value to create internal object. - Component uses
propPatches
to update internal object in imperative way.
The current behavior
- Component is not responsible to
prop
updates anymore, it care only aboutpropPatches
. - If
prop
update doesn’t come fromimmerjs
, than user have to providepropPatches
by himself: find minimal changes to makenextProp
equal toprevProp
(DSU, tries, etc).
The expected behavior
- Component should be responsible for
prop
value. - User should be able to provide only
prop
value withoutpropPatches
.
Please add recommendation into documentation: produceWithPatches
from immerjs
is not recommended for react
. Thank you.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (1 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m struggling to understand what is being suggested in this issue. There are infinitely many ways to use React, and generally there are some idiomatic patterns that you can find on the website. I don’t know enough about patches to confidently say whether this usage is idiomatic or not, but it’s also not common enough to warrant a notice on the React website either way. If this is something you feel strongly about, it sounds like a good candidate for a blog post on a personal blog.
@mweststrate, @gaearon Hello, you can’t find today many applications that uses
patches
as property to feed internal instance in imperative way. But if it will become popular enough than you will know what approach to move into not recommended list.If you think that today this pattern is not important than issue can be closed, ok.