diff --git a/src/types.ts b/src/types.ts index 9364276..bd81afd 100644 --- a/src/types.ts +++ b/src/types.ts @@ -5,3 +5,7 @@ export interface UseModel { (depsFn?: Deps): T; data?: T; } + +export interface Config { + forwardRef: Boolean; +} diff --git a/src/with-model.tsx b/src/with-model.tsx index 0a28b29..4b446e8 100644 --- a/src/with-model.tsx +++ b/src/with-model.tsx @@ -1,6 +1,6 @@ import React, { ComponentType, FC, NamedExoticComponent } from "react"; import { NonReactStatics } from "hoist-non-react-statics"; -import { UseModel } from "./types"; +import { UseModel, Config } from "./types"; export type Omit = Pick>; @@ -47,15 +47,18 @@ type MapModelToProps = ( export function withModel( useModel: UseModel, - mapModelToProps: MapModelToProps + mapModelToProps: MapModelToProps, + config?: Config ): InferableComponentEnhancerWithProps; export function withModel( useModels: UseModel[], - mapModelToProps: MapModelToProps + mapModelToProps: MapModelToProps, + config?: Config ): InferableComponentEnhancerWithProps; export function withModel( useModelOrUseModels: UseModel | UseModel[], - mapModelToProps: MapModelToProps + mapModelToProps: MapModelToProps, + config: Config = { forwardRef: true } ) { return function(C) { const Wrapper: FC = function(props) { @@ -72,7 +75,10 @@ export function withModel( } const componentProps = { ...props, - ...modelProps + ...modelProps, + ...{ + ref: config.forwardRef ? props.onRef : undefined + } }; return ; };