-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
suggestion: recompose examples #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
That's an interesting suggestion, unfortunately I'm not using recompose on daily basis but this is something I was interested in learning at some point. |
@arolson101 why do you think recompose examples belongs here? I believe it's completely different topic |
@R00GER for example, the |
In my case I have been using something like this:
import React from 'react';
import { compose } from 'recompose';
import { withTranslations, WithTranslationsProps } from './i18n';
import { toggable, ToggableHandlers, ToggableState } from './toggable';
export type ComponentOwnProps = {
className?: string;
disabled?: boolean;
bar: string;
}
export type ComponentProps = ComponentOwnProps
& WithTranslationsProps
& ToggableHandlers
& ToggableState;
export const Component = compose<ComponentProps, ComponentOwnProps>(
withTranslations,
toggable,
)((props: ComponentProps) => {
const { className, disabled, toggle, isOpen, i18n } = props;
return (
<div className={className} disabled={disabled}>
<button onClick={toggle}>{isOpen ? i18n('Close') : i18n('Open')}</button>
</div>
);
});
export type ToggableState = typeof initState;
export type ToggableHandlers = {
toggle: () => ToggableState;
setIsOpen: (isOpen: boolean) => ToggableState;
};
const initState = {
isOpen: false,
};
const handlers = {
toggle: (state: ToggableState) => () => ({ isOpen: !state.isOpen }),
setIsOpen: () => (isOpen: boolean) => ({ isOpen }),
};
export const toggable = Recompose.withStateHandlers<
ToggableState,
ToggableHandlers
>(initState, handlers); Hope it helps |
@BoostIO funded this issue with $10. Visit this issue on Issuehunt |
@loadbalance-sudachi-kun funded this issue with $256. Visit this issue on Issuehunt |
@piotrwitek has started working. Visit this issue on Issuehunt |
@piotrwitek has submitted output. Visit this issue on Issuehunt |
Planned work:
|
https://github.com/acdlite/recompose
|
I think we should move to hooks instead |
I found this document to be very helpful! Thank you for putting it together.
It might be useful to add some typescript examples of recompose
The text was updated successfully, but these errors were encountered: