Skip to content

Instantly share code, notes, and snippets.

@ryerh
Last active December 7, 2022 13:46
Show Gist options
  • Save ryerh/f29668b4356233f4899644daaae9e675 to your computer and use it in GitHub Desktop.
Save ryerh/f29668b4356233f4899644daaae9e675 to your computer and use it in GitHub Desktop.
multiple react component decorators in typescript
import * as React from 'react';
import { withRouter } from 'react-router-dom';
import { RouteComponentProps, Form } from 'antd';
import compose from './compose';
interface DecoratorProps {
id: number;
}
type OwnProps = RouteComponentProps;
const finalDecorator = compose<DecoratorProps>(
withRouter,
Form.create(),
);
class ApplyForm extends React.Component<OwnProps> {
render() {}
}
export default finalDecorator(ApplyForm);
import * as React from 'react';
// React Component
type RC<P> = React.SFC<P> | React.ComponentClass<P>;
// High order Component
type HOC<P> = (C: RC<P>) => RC<P>;
// Compose multiple hocs into single hoc
export default function compose<P>(...hocs: Array<HOC<any>>): HOC<P> {
return (C: RC<P>) => hocs.reduce((component, hoc) => hoc(component), C);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment