Skip to content

Commit f9f791b

Browse files
committed
Revert "Fix React 18.0.0 compatibility by using React namespace imports"
This reverts commit 7a9f539.
1 parent 7a9f539 commit f9f791b

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

packages/react-on-rails-pro/src/RSCProvider.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
'use client';
1616

17-
import * as React from 'react';
18-
import { type ReactNode } from 'react';
17+
import { createContext, useContext, type ReactNode } from 'react';
1918
import type { ClientGetReactServerComponentProps } from './getReactServerComponent.client.ts';
2019
import { createRSCPayloadKey } from './utils.ts';
2120

@@ -25,7 +24,7 @@ type RSCContextType = {
2524
refetchComponent: (componentName: string, componentProps: unknown) => Promise<ReactNode>;
2625
};
2726

28-
const RSCContext = React.createContext<RSCContextType | undefined>(undefined);
27+
const RSCContext = createContext<RSCContextType | undefined>(undefined);
2928

3029
/**
3130
* Creates a provider context for React Server Components.
@@ -102,7 +101,7 @@ export const createRSCProvider = ({
102101
* ```
103102
*/
104103
export const useRSC = () => {
105-
const context = React.useContext(RSCContext);
104+
const context = useContext(RSCContext);
106105
if (!context) {
107106
throw new Error('useRSC must be used within a RSCProvider');
108107
}

packages/react-on-rails-pro/src/RSCRoute.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@
1616

1717
'use client';
1818

19-
import * as React from 'react';
20-
import { type ReactNode } from 'react';
19+
import { Component, use, type ReactNode } from 'react';
2120
import { useRSC } from './RSCProvider.tsx';
2221
import { ServerComponentFetchError } from './ServerComponentFetchError.ts';
2322

2423
/**
2524
* Error boundary component for RSCRoute that adds server component name and props to the error
2625
* So, the parent ErrorBoundary can refetch the server component
2726
*/
28-
class RSCRouteErrorBoundary extends React.Component<
27+
class RSCRouteErrorBoundary extends Component<
2928
{ children: ReactNode; componentName: string; componentProps: unknown },
3029
{ error: Error | null }
3130
> {
@@ -77,8 +76,8 @@ export type RSCRouteProps = {
7776
};
7877

7978
const PromiseWrapper = ({ promise }: { promise: Promise<ReactNode> }) => {
80-
// React.use is available in React 18.3+
81-
const promiseResult = React.use(promise);
79+
// use is available in React 18.3+
80+
const promiseResult = use(promise);
8281

8382
// In case that an error happened during the rendering of the RSC payload before the rendering of the component itself starts
8483
// RSC bundle will return an error object serialized inside the RSC payload

0 commit comments

Comments
 (0)