How to use recompose - 10 common examples

To help you get started, we’ve selected a few recompose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flow-typed / flow-typed / definitions / npm / recompose_v0.26.x / flow_v0.57.x-v0.87.x / test_onlyUpdateForKeys.js View on Github external
);

const enhacer: HOC<*, EnhancedCompProps> = compose(
  onlyUpdateForKeys(["eA"]),
  withProps(props => ({
    eA: (props.eA: number),
    // $ExpectError eA nor any nor string
    eAErr: (props.eA: string)
  })),
  withProps(props => ({
    // $ExpectError property not found
    err: props.iMNotExists
  }))
);

const enhacerErr: HOC<*, EnhancedCompProps> = compose(
  // $ExpectError property not found
  onlyUpdateForKeys(["eB"])
);

const EnhancedComponent = enhacer(Comp);
github flow-typed / flow-typed / definitions / npm / recompose_v0.26.x / flow_v0.47.x-v0.52.x / test_withContext.js View on Github external
(eA: string)
    }
  ;

const enhacer: HOC<*, EnhancedCompProps> = compose(
  withContext({}, props => {
    // $ExpectError eA nor any nor string
    (props.eA: string);
    return {};
  }),
  withProps(props => ({
    eA: (props.eA: number),
    // $ExpectError eA nor any nor string
    eAErr: (props.eA: string)
  })),
  withProps(props => ({
    // $ExpectError property not found
    err: props.iMNotExists
  }))
);

const EnhancedComponent = enhacer(Comp);
github flow-typed / flow-typed / definitions / npm / recompose_v0.26.x / flow_v0.47.x-v0.52.x / test_defaultProps.js View on Github external
const Comp = ({ hello, eA }) =>
  <div>
    {(hello: string)}
    {(eA: number)}
    {
      // $ExpectError eA nor any nor string
      (eA: string)
    }
    {
      // $ExpectError hello nor any nor number
      (hello: number)
    }
  </div>;

const enhacer: HOC&lt;*, EnhancedCompProps&gt; = compose(
  defaultProps({
    hello: "world"
  }),
  withProps(props =&gt; ({
    hello: (props.hello: string),
    eA: (props.eA: number),
    // $ExpectError hello nor any nor number
    helloErr: (props.hello: number),
    // $ExpectError eA nor any nor string
    eAErr: (props.eA: string)
  })),
  withProps(props =&gt; ({
    // $ExpectError property not found
    err: props.iMNotExists
  }))
);
github bowtie-co / houndstooth-ui / src / components / molecules / Field / Document / DocumentContainer.jsx View on Github external
// conditional functions here:
const nullConditionFn = (props) =&gt; !props
const showDocPreviewConditionFn = (props) =&gt; props.preview || props.previewOnly

export default compose(
  withRouter,
  withMaybe(nullConditionFn),
  withState('numPages', 'setNumPages', null),
  withState('pageNumber', 'setPageNumber', 1),
  withState('preview', 'setPreview', false),
  withPropsOnChange([ 'value' ], ({ value, setPreview }) =&gt; {
    if (value) {
      setPreview(true)
    }
  }),
  withHandlers({
    togglePreview: ({ preview, setPreview }) =&gt; (e) =&gt; {
      e.preventDefault()
      e.stopPropagation()

      setPreview(!preview)
    },
    customTextRenderer: (props) =&gt; (item) =&gt; {
      console.log('customTextRenderer', item)
    },
    handleTextLoaded: ({ onTextLoaded }) =&gt; () =&gt; {
      if (typeof onTextLoaded === 'function') {
        onTextLoaded()
      }
    },
    handlePage: ({ setPageNumber, numPages }) =&gt; (page) =&gt; {
      if (page &gt; 0 &amp;&amp; page &lt;= numPages) {
github grommet / grommet / grommet / src / js / components / CheckBox / CheckBox.js View on Github external
&gt;
        {first}
        {second}
      
    );
  }
}

CheckBox.defaultProps = {};
Object.setPrototypeOf(CheckBox.defaultProps, defaultProps);

let CheckBoxDoc;
if (process.env.NODE_ENV !== 'production') {
  CheckBoxDoc = require('./doc').doc(CheckBox); // eslint-disable-line global-require
}
const CheckBoxWrapper = compose(
  withFocus(),
  withTheme,
  withForwardRef,
)(CheckBoxDoc || CheckBox);

export { CheckBoxWrapper as CheckBox };
github NCI-GDC / portal-ui / src / packages / @ncigdc / components / FacetSelection.js View on Github external
fontStyle: 'italic',
    color: '#525252',
  },
};

// Highlighting is frustratingly slow with &gt; 100 items
const ConditionalHighlight = ({ condition, search, children }) =&gt;
  condition ? (
    {children}
  ) : (
    <span>{children}</span>
  );

export default compose(
  withState('facetMapping', 'setFacetMapping', {}),
  withState('query', 'setQuery', ''),
  withState('focusedFacet', 'setFocusedFacet', null),
  withState('isLoadingFacetMapping', 'setIsLoadingFacetMapping', false),
  withState(
    'isLoadingAdditionalFacetData',
    'setIsLoadingAdditionalFacetData',
    false,
  ),
  withPropsOnChange(
    ['isLoadingFacetMapping', 'isLoadingAdditionalFacetData'],
    ({ isLoadingFacetMapping, isLoadingAdditionalFacetData }) =&gt; ({
      isLoading: _.some([isLoadingFacetMapping, isLoadingAdditionalFacetData]),
    }),
  ),
  withState('shouldHideUselessFacets', 'setShouldHideUselessFacets', false),
  withProps(
    ({
github prescottprue / fireadmin / src / routes / Projects / routes / Project / routes / Actions / components / RecentActions / RecentActions.enhancer.js View on Github external
orderBy: ['createdAt', 'desc'],
      limit: 3,
      storeAs: `recentActions-${projectId}`
    }
  ]),
  // Map redux state to props
  connect(({ firebase, firestore }, { projectId }) => ({
    displayNames: get(firebase, 'data.displayNames'),
    recentActions: get(firestore, `ordered.recentActions-${projectId}`),
    environments: get(firestore, `data.environments-${projectId}`)
  })),
  // Show a loading spinner while actions are loading
  spinnerWhileLoading(['recentActions']),
  // Render NoRecentActions component if no recent actions exist
  renderWhileEmpty(['recentActions'], NoRecentActions),
  withProps(({ recentActions, displayNames, environments }) => ({
    orderedActions: map(recentActions, event => {
      const createdBy = get(event, 'createdBy')
      const envLabelFromEnvironmentValIndex = (envIndex = 0) => {
        const envKey = get(event, `eventData.environmentValues.${envIndex}`)
        const envName = get(environments, `${envKey}.name`)
        const envUrl =
          get(environments, `${envKey}.databaseURL`) ||
          get(event, `eventData.inputValues.${envIndex}.databaseURL`, '')
        const firebaseProjectName = databaseURLToProjectName(envUrl)
        return `${envName} (${firebaseProjectName})`
      }
      if (createdBy) {
        return {
          ...event,
          src: envLabelFromEnvironmentValIndex(0),
          dest: envLabelFromEnvironmentValIndex(1),
github TEAM-OSTRICH / SYS-DIFFER / src / client / containers / MainContainer.jsx View on Github external
handleSelect={handleSelect}
                selectAll={selectAll}
              /&gt;
            )
            : null}
          {/* {scriptDisplay ?  : null} */}
          {/* {saveLoadDisplay ?  : null} */}
      
    );
    /* eslint-enable */
  }
}


// export default withRouter(MainContainer);
export default compose(
  withRouter,
  withStyles(),
)(MainContainer);
github withspectrum / spectrum / src / components / profile / user.js View on Github external
initMessage()}
                tipText={`Message ${user.name}`}
                tipLocation={'top-left'}
              /&gt;
            )}
          
        
      );
  }
};

const User = compose(
  displayLoadingCard,
  withRouter,
  withCurrentUser
)(UserWithData);
const mapStateToProps = state =&gt; ({
  initNewThreadWithUser: state.directMessageThreads.initNewThreadWithUser,
});
// $FlowFixMe
export default connect(mapStateToProps)(User);
github istarkov / google-map-clustering-example / src / markers / ClusterMarker.js View on Github external
style={{
          transform: `translate3D(0,0,0) scale(${scale}, ${scale})`,
        }}
      &gt;
        <div>
          {text}
        </div>
      
    )
  }
  
);

export const clusterMarkerHOC = compose(
  defaultProps({
    text: '0',
    styles: clusterMarkerStyles,
    initialScale: 0.6,
    defaultScale: 1,
    hoveredScale: 1.15,
    hovered: false,
    stiffness: 320,
    damping: 7,
    precision: 0.001,
  }),
  // pure optimization can cause some effects you don't want,
  // don't use it in development for markers
  pure,
  withPropsOnChange(
    ['initialScale'],