2

I've created a recompose lifecycle HOC... See the code for component to see how I am using the HOC with my components.

Is there a way to avoid needing to describe the PropTypes for the HOC wrapping:

Component:

import React from 'react';
import PropTypes from 'prop-types';

const MyPage = () => (
  <div>stuff</div>
);

const WrappedMyPage = withMyCustomThing({
  a: 'value',
  b: 'value',
})(MyPage);

WrappedMyPage.contextTypes = {
  myItem: PropTypes.object.isRequired,
};

export default WrappedMyPage;

HOC Recompose Lifecycle

import { lifecycle } from 'recompose';

function withMyCustomThing() {
  return lifecycle({
  ....

export default withMyCustomThing;
AnnaSm
  • 2,190
  • 6
  • 22
  • 32
  • I don't quite understand the question. Nobody forces you to use prop-types, it's completely optional. Or do you have a linter that issues a warning about missing prop types? – Patrick Hund Dec 28 '17 at 18:44
  • no linter issues would just like to minimize the hoc footprint outside of the HOC. Is there a way to move the propTypes inside of the HOC? – AnnaSm Dec 29 '17 at 17:54
  • recompose has its own setPropTypes() prop checker so you could compose your final component so that it checks props in a hoc first then does the lifecycle thing https://github.com/acdlite/recompose/blob/master/docs/API.md#setproptypes – Josh Pittman Jan 12 '18 at 05:09

0 Answers0