Skip to content

Commit

Permalink
fix: Forward Refs in React SDK HOC (#862)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajwootto authored May 22, 2024
1 parent aee5894 commit c2d5ad1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/nx-affected-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
run: yarn affected:e2e
env:
E2E_NEXTJS_SERVER_KEY: ${{ secrets.E2E_NEXTJS_SERVER_KEY }}
NEXT_PUBLIC_E2E_NEXTJS_KEY: ${{ secrets.NEXT_PUBLIC_E2E_NEXTJS_CLIENT_KEY }}
NEXT_PUBLIC_E2E_NEXTJS_CLIENT_KEY: ${{ secrets.NEXT_PUBLIC_E2E_NEXTJS_CLIENT_KEY }}
DVC_E2E_SERVER_SDK_KEY: ${{ secrets.DVC_E2E_SERVER_SDK_KEY }}
- name: Upload Playwright Report
Expand Down
25 changes: 16 additions & 9 deletions sdk/react/src/withDevCycleProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
import { ProviderConfig } from './types'
import React from 'react'
import React, {
forwardRef,
ForwardRefExoticComponent,
PropsWithoutRef,
RefAttributes,
} from 'react'
import hoistNonReactStatics from 'hoist-non-react-statics'
import { DevCycleProvider } from './DevCycleProvider'

export function withDevCycleProvider<T extends object>(
config: ProviderConfig,
): (WrappedComponent: React.ComponentType<T>) => React.ComponentType<T> {
return (WrappedComponent) => {
const HoistedComponent = (props: T) => {
export const withDevCycleProvider =
<T extends object>(config: ProviderConfig) =>
(
WrappedComponent: React.ComponentType<T>,
): ForwardRefExoticComponent<
PropsWithoutRef<T> & RefAttributes<unknown>
> => {
const HoistedComponent = forwardRef((props: T, ref) => {
return (
<DevCycleProvider config={config}>
<WrappedComponent {...props} />
<WrappedComponent {...props} ref={ref} />
</DevCycleProvider>
)
}
})

hoistNonReactStatics(HoistedComponent, WrappedComponent)

return HoistedComponent
}
}

/**
* @deprecated Use withDevCycleProvider instead
Expand Down

0 comments on commit c2d5ad1

Please sign in to comment.