-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[withState improvement] #243
Comments
You could always update multiple values now: withState('obj', 'setObj', { name: '', description: ''})
....
withHandlers({
changeDescriptionAndName: ({ setObj }) => ({ name, description }) => {
setObj(o => ({...o, name, description }))
},
changeDescription: ({ setObj }) => ({ description }) => {
setObj(o => ({...o, description }))
}
}) So sorry, but I don't think that your PR will make something simpler or easier. |
Respectfully, I think that approach has some downsides:
So the question is whether that downside is worth adding the extra lines of code to the project / another export that needs to be unit tested. |
PS: |
Perhaps you feel you're being helpful, but your comments come across as condescending. Rather than imply I don't know how to use "modern js" (or make it seem like users of this library who aren't using FlowType / es6 / babel are bad or wrong), can you just take it at face value that I do use devTools and that removing the (Not to mention it will as a matter of fact require less calls to On top of that, I don't get the impression that you're trying to hear what I'm saying to begin with. What I'm talking about is that you are asking me to change my component's prop signature into accepting { name, description } as a single prop. It is natural to write:
It is NOT natural to write
The problem here isn't the label "obj". The problem is that now my functional component needs to change its signature based on how its being enhanced. My component needs to know about the structure of the enhancers to know which props came from which object. That's not a good pattern. But yeah, I can drop this and implement it myself as a separate lib, peace. |
Ok. I'll try to explain in other words. You could look here #182 and see that composition could be done in a way where just one upper level component will be created, but read this comment #182 (comment) |
Typescript 2.1 now has type safety for string lookups, so that shouldn't be an issue once the typings are updated. https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html |
Can be further discussed in #308. Closed now. |
Hi,
Love the lib / work, thanks for this.
One suggested improvement:
Currently,
withState
can only accept a single string arg for the stateKey and updater.If I want multiple keys / updaters, I have to wrap with
withState
multiple times, which according to my React dev tools creates multiple HOC:withState(withState(MyComponent))
Suggested alternate API signature (would not affect any existing calls):
If this seems reasonable I'm happy to work on a PR
The text was updated successfully, but these errors were encountered: