piotrwitek/react-redux-typescript-guide

Do you want to work on this issue?

You can request for a bounty in order to promote it!

suggestion: recompose examples #46

arolson101 posted onGitHub

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


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 :)

posted by piotrwitek over 7 years ago

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

posted by pablobirukov about 7 years ago

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

posted by arolson101 about 7 years ago

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

posted by IOuser over 6 years ago

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

posted by IssueHuntBot over 6 years ago

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

posted by IssueHuntBot over 6 years ago

@piotrwitek has started working. Visit this issue on Issuehunt

posted by IssueHuntBot over 6 years ago

@piotrwitek has submitted output. Visit this issue on Issuehunt

posted by IssueHuntBot over 6 years ago

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.)
posted by piotrwitek over 6 years ago

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.

posted by muescha about 6 years ago

I think we should move to hooks instead

posted by sibelius about 5 years ago

Fund this Issue

Only logged in users can fund an issue

Pull requests

Recent activities

boostio funded 10.00 for piotrwitek/react-redux-typescript-guide# 46
over 6 years ago