Skip to content

Commit

Permalink
refactor(react)!: require React 19 as peer dependency (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
tien authored Feb 23, 2025
1 parent 9a2c9ad commit 9de08c9
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 46 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-cougars-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@reactive-dot/react": minor
---

BREAKING CHANGE: required React 19 as peer dependency.
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
"vitest": "^3.0.6"
},
"peerDependencies": {
"react": "18.x || 19.x"
"react": "19.x"
}
}
5 changes: 1 addition & 4 deletions packages/react/src/contexts/chain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ export type ChainProviderProps = PropsWithChildren<{
*/
export function ChainProvider(props: ChainProviderProps) {
return (
// eslint-disable-next-line @eslint-react/no-context-provider
<ChainIdContext.Provider value={props.chainId}>
{props.children}
</ChainIdContext.Provider>
<ChainIdContext value={props.chainId}>{props.children}</ChainIdContext>
);
}
12 changes: 4 additions & 8 deletions packages/react/src/contexts/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@ export function ReactiveDotProvider({
children,
}: ReactiveDotProviderProps) {
return (
// eslint-disable-next-line @eslint-react/no-context-provider
<ConfigContext.Provider value={config}>
{/* eslint-disable-next-line @eslint-react/no-context-provider */}
<MutationEventSubjectContext.Provider
value={useMemo(() => new Subject(), [])}
>
<ConfigContext value={config}>
<MutationEventSubjectContext value={useMemo(() => new Subject(), [])}>
<Suspense>
<WalletsInitializer />
</Suspense>
{children}
</MutationEventSubjectContext.Provider>
</ConfigContext.Provider>
</MutationEventSubjectContext>
</ConfigContext>
);
}

Expand Down
7 changes: 1 addition & 6 deletions packages/react/src/contexts/signer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,5 @@ export type SignerProviderProps = PropsWithChildren<{
* @returns React element
*/
export function SignerProvider(props: SignerProviderProps) {
return (
// eslint-disable-next-line @eslint-react/no-context-provider
<SignerContext.Provider value={props.signer}>
{props.children}
</SignerContext.Provider>
);
return <SignerContext value={props.signer}>{props.children}</SignerContext>;
}
10 changes: 4 additions & 6 deletions packages/react/src/hooks/use-chain-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { ChainIdContext } from "../contexts/chain.js";
import type { ChainHookOptions } from "./types.js";
import { useConfig } from "./use-config.js";
import { type ChainId, ReactiveDotError } from "@reactive-dot/core";
// eslint-disable-next-line @eslint-react/no-use-context
import { useContext } from "react";
import { use } from "react";

/**
* Hook for getting all configured chain IDs.
Expand All @@ -20,8 +19,7 @@ export function useChainIds() {
* @returns The current chain ID
*/
export function useChainId() {
// eslint-disable-next-line @eslint-react/no-use-context
const chainId = useContext(ChainIdContext);
const chainId = use(ChainIdContext);

if (chainId === undefined) {
throw new ReactiveDotError("No chain ID provided");
Expand All @@ -39,8 +37,8 @@ export function internal_useChainId<TOptionalChainId extends boolean = false>({
}: ChainHookOptions & {
optionalChainId?: TOptionalChainId;
} = {}) {
// eslint-disable-next-line @eslint-react/no-use-context, react-hooks/rules-of-hooks
const contextChainId = useContext(ChainIdContext);
// eslint-disable-next-line react-hooks/rules-of-hooks
const contextChainId = use(ChainIdContext);
const chainId = options?.chainId ?? contextChainId;

if (!optionalChainId && chainId === undefined) {
Expand Down
6 changes: 2 additions & 4 deletions packages/react/src/hooks/use-config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { ConfigContext } from "../contexts/config.js";
import { ReactiveDotError } from "@reactive-dot/core";
// eslint-disable-next-line @eslint-react/no-use-context
import { useContext } from "react";
import { use } from "react";

/**
* Hook for getting the current config.
*
* @returns The current config
*/
export function useConfig() {
// eslint-disable-next-line @eslint-react/no-use-context
const config = useContext(ConfigContext);
const config = use(ConfigContext);

if (config === undefined) {
throw new ReactiveDotError("No config provided");
Expand Down
6 changes: 2 additions & 4 deletions packages/react/src/hooks/use-mutation-effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ import {
type MutationEvent,
MutationEventSubjectContext,
} from "../contexts/mutation.js";
// eslint-disable-next-line @eslint-react/no-use-context
import { useContext, useEffect } from "react";
import { use, useEffect } from "react";

/**
* Hook that watches for mutation events.
*
* @param effect - Callback when new mutation event is emitted
*/
export function useMutationEffect(effect: (event: MutationEvent) => void) {
// eslint-disable-next-line @eslint-react/no-use-context
const mutationEventSubject = useContext(MutationEventSubjectContext);
const mutationEventSubject = use(MutationEventSubjectContext);

useEffect(() => {
const subscription = mutationEventSubject.subscribe({ next: effect });
Expand Down
9 changes: 3 additions & 6 deletions packages/react/src/hooks/use-mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import type {
TxObservable,
TypedApi,
} from "polkadot-api";
// eslint-disable-next-line @eslint-react/no-use-context
import { useCallback, useContext } from "react";
import { use, useCallback } from "react";
import { from } from "rxjs";
import { catchError, switchMap, tap } from "rxjs/operators";

Expand Down Expand Up @@ -57,10 +56,8 @@ export function useMutation<
) {
const config = useConfig();
const chainId = internal_useChainId(options);
// eslint-disable-next-line @eslint-react/no-use-context
const mutationEventSubject = useContext(MutationEventSubjectContext);
// eslint-disable-next-line @eslint-react/no-use-context
const contextSigner = useContext(SignerContext);
const mutationEventSubject = use(MutationEventSubjectContext);
const contextSigner = use(SignerContext);

return useAsyncAction(
useAtomCallback(
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/hooks/use-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { preflight, query } from "@reactive-dot/core/internal/actions.js";
import { type Atom, atom, useAtomValue, type WritableAtom } from "jotai";
import { atomWithObservable, atomWithRefresh } from "jotai/utils";
import { version as reactVersion, useMemo } from "react";
import { useMemo } from "react";
import { from, type Observable } from "rxjs";
import { switchMap } from "rxjs/operators";

Expand Down Expand Up @@ -58,7 +58,7 @@ export function useLazyLoadQuery<
[hashKey],
),
// TODO: remove once https://github.com/pmndrs/jotai/issues/2847 is fixed
reactVersion.startsWith("19.") ? { delay: 0 } : undefined,
{ delay: 0 },
);

return useMemo(
Expand Down
6 changes: 2 additions & 4 deletions packages/react/src/hooks/use-signer.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { SignerContext } from "../contexts/signer.js";
// eslint-disable-next-line @eslint-react/no-use-context
import { useContext } from "react";
import { use } from "react";

/**
* Hook for getting the current signer.
*
* @returns The current signer
*/
export function useSigner() {
// eslint-disable-next-line @eslint-react/no-use-context
return useContext(SignerContext);
return use(SignerContext);
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5078,7 +5078,7 @@ __metadata:
typescript: "npm:^5.7.3"
vitest: "npm:^3.0.6"
peerDependencies:
react: 18.x || 19.x
react: 19.x
languageName: unknown
linkType: soft

Expand Down

0 comments on commit 9de08c9

Please sign in to comment.