Skip to content

Commit

Permalink
Merge pull request #5528 from GeekyAnts/feat/factory-state
Browse files Browse the repository at this point in the history
feat/factory-state
  • Loading branch information
ankit-tailor committed Nov 3, 2022
2 parents baa5af5 + 8a84829 commit 4dbfc42
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/factory/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ export default function Factory<P>(
componentTheme?: ComponentTheme
) {
return React.forwardRef(
({ children, ...props }: P & FactoryComponentProps, ref: any) => {
({ children, state, ...props }: P & FactoryComponentProps, ref: any) => {
const StyledComponent = useMemo(() => makeStyledComponent(Component), []);
const calculatedProps = usePropsWithComponentTheme(
componentTheme ?? {},
props
props,
state
);
return (
<StyledComponent {...(calculatedProps as P)} ref={ref}>
Expand Down
2 changes: 2 additions & 0 deletions src/factory/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { PlatformProps } from '../components/types';
import type { StyledProps } from '../theme/types';
import type { IStateProps } from '../hooks/useThemeProps/propsFlattener';

export type FactoryComponentProps = StyledProps &
PlatformProps<StyledProps> & {
children?: string | JSX.Element | JSX.Element[];
state?: IStateProps;
};
6 changes: 4 additions & 2 deletions src/hooks/useThemeProps/usePropsWithComponentTheme.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { usePropsResolutionWithComponentTheme } from './usePropsResolution';
import type { ComponentTheme } from '../../theme';
import type { IStateProps } from './propsFlattener';

export function usePropsWithComponentTheme(
localTheme: ComponentTheme,
propsReceived: any
propsReceived: any,
state?: IStateProps
) {
return usePropsResolutionWithComponentTheme(localTheme, propsReceived);
return usePropsResolutionWithComponentTheme(localTheme, propsReceived, state);
}

0 comments on commit 4dbfc42

Please sign in to comment.