Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(react)!: require React 19 as peer dependency #514

Merged
merged 1 commit into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 @@
* @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);

Check warning on line 22 in packages/react/src/hooks/use-chain-id.ts

View check run for this annotation

Codecov / codecov/patch

packages/react/src/hooks/use-chain-id.ts#L22

Added line #L22 was not covered by tests

if (chainId === undefined) {
throw new ReactiveDotError("No chain ID provided");
Expand All @@ -39,8 +37,8 @@
}: 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);

Check warning on line 41 in packages/react/src/hooks/use-chain-id.ts

View check run for this annotation

Codecov / codecov/patch

packages/react/src/hooks/use-chain-id.ts#L41

Added line #L41 was not covered by tests
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);

Check warning on line 11 in packages/react/src/hooks/use-config.ts

View check run for this annotation

Codecov / codecov/patch

packages/react/src/hooks/use-config.ts#L11

Added line #L11 was not covered by tests

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 @@
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);

Check warning on line 13 in packages/react/src/hooks/use-mutation-effect.ts

View check run for this annotation

Codecov / codecov/patch

packages/react/src/hooks/use-mutation-effect.ts#L13

Added line #L13 was not covered by tests

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 @@
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,11 +56,9 @@
) {
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);

Check warning on line 61 in packages/react/src/hooks/use-mutation.ts

View check run for this annotation

Codecov / codecov/patch

packages/react/src/hooks/use-mutation.ts#L59-L61

Added lines #L59 - L61 were not covered by tests
return useAsyncAction(
useAtomCallback(
useCallback(
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);

Check warning on line 10 in packages/react/src/hooks/use-signer.ts

View check run for this annotation

Codecov / codecov/patch

packages/react/src/hooks/use-signer.ts#L10

Added line #L10 was not covered by tests
}
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