Skip to content

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

Open
arolson101 opened this issue Jan 19, 2018 · 11 comments
Open

suggestion: recompose examples #46

arolson101 opened this issue Jan 19, 2018 · 11 comments

Comments

@arolson101
Copy link

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

@piotrwitek
Copy link
Owner

piotrwitek commented Jan 20, 2018

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.
btw. contributions are welcomed :)

@pablobirukov
Copy link

@arolson101 why do you think recompose examples belongs here? I believe it's completely different topic

@arolson101
Copy link
Author

@R00GER for example, the withState example is a recompose component. They're just useful for making higher order components.

@IOuser
Copy link

IOuser commented Aug 22, 2018

In my case I have been using something like this:

component.tsx

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>
    );
});

toggable.tsx

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

@IssueHuntBot
Copy link

@BoostIO funded this issue with $10. Visit this issue on Issuehunt

@IssueHuntBot
Copy link

@loadbalance-sudachi-kun funded this issue with $256. Visit this issue on Issuehunt

@IssueHuntBot
Copy link

@piotrwitek has started working. Visit this issue on Issuehunt

@piotrwitek piotrwitek self-assigned this Sep 17, 2018
@IssueHuntBot
Copy link

@piotrwitek has submitted output. Visit this issue on Issuehunt

@piotrwitek
Copy link
Owner

Planned work:

  • add a new recompose section with setup instructions
  • add usage code examples of the most common recompose API in the playground project
  • add autogeneration of docs based on code examples based on their implementation
  • include code examples in the build pipeline (format, lint, typecheck etc.)

@muescha
Copy link

muescha commented Apr 6, 2019

https://github.com/acdlite/recompose

A Note from the Author (acdlite, Oct 25 2018):
Hi! I created Recompose about three years ago. About a year after that, I joined the React team. Today, we announced a proposal for Hooks. Hooks solves all the problems I attempted to address with Recompose three years ago, and more on top of that. I will be discontinuing active maintenance of this package (excluding perhaps bugfixes or patches for compatibility with future React releases), and recommending that people use Hooks instead. Your existing code with Recompose will still work, just don't expect any new features. Thank you so, so much to @wuct and @istarkov for their heroic work maintaining Recompose over the last few years.

@sibelius
Copy link

I think we should move to hooks instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants