-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[HOC suggestion] withToggle #244
Comments
Hi ;-), For example I use So in my I wrote about in some other issues, it's easier to think about recompose as about a base blocks for your own hocs. This will allow to make recompose API surface as small as possible. It's so easy to compose multiple hocs and reuse everywhere in your code. export default (keyName, keySetterName, initialValue) => compose(
withState(keyName, keySetterName, initialValue),
...blabla
) |
Thanks. I was mistaken earlier - I just checked and (for clarity, my comment: |
You are again talking about
Please be more clear, what use case are you talking about? |
Never mind, editing my post. |
Personally i create separate modules like import { withHandlers } from 'recompose';
import { withStateToggle } from 'recompose-addons'; |
I am curious if @istarkov can elaborate on his approach with some code examples. He said:
What does that look like? |
@timkindberg The problem of |
I am going to close this issue because it's no longer active. Please feel free to reopen it if you have further input. |
Hi,
A common use case for
withState
is a simple toggle. Right now, a combination ofwithState
andmapProps
needs to be used for this:or the calling Component needs to explicitly include the new state:
<Button onClick={() => toggleKey(!key) />
Neither of these is a huge hassle or roadblock, but it might be nice to encapsulate this common pattern by including a
withStateToggle
HOC that accomplishes this precise pattern:withStateToggle('key', 'toggleKey', true)
<Button onClick={toggleKey} />
Happy to write a PR.
The text was updated successfully, but these errors were encountered: