-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
QueryClientProvider type issue after upgrading to React 18 #3476
Comments
Because react changed how FunctionComponent is defined. v18: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L510 v17: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/v17/index.d.ts#L542 in v18, FunctionComponent doesnt have any relationship with PropsWithChildren. |
As a workaround I did this import "react";
declare module "react" {
export type FC<P = {}> = FunctionComponent<P>;
export interface FunctionComponent<P = {}> {
(props: PropsWithChildren<P>, context?: any): ReactElement<any, any> | null;
propTypes?: WeakValidationMap<P> | undefined;
contextTypes?: ValidationMap<any> | undefined;
defaultProps?: Partial<P> | undefined;
displayName?: string | undefined;
}
} in and everything worked fine. lol |
@mustafaabobakr Did it even work even if the error is coming from a 3rd party component?In my case, the error occurs with react-query and me adding the above code in index.d.ts is not fixing it. |
@a2441918 https://twitter.com/mustafaabobakr_/status/1512176988353703945 |
@mustafaabobakr Where does your index.d.ts sit? In the src folder? |
For anyone who is looking for a less aggressive workaround: declare module "react-query/types/react/QueryClientProvider" {
interface QueryClientProviderProps {
children?: ReactNode;
}
} |
That "aggressive" workaround is also for React.FC components Either that or downgrade to v17 types. https://twitter.com/mustafaabobakr_/status/1512176988353703945?t=92vWtLsOH3RnNR7uuYuTCA&s=19 |
If you did upgrade to the @types/react v18 I submitted a PR for review, if you are after a quick fix and use NPM (sorry not sure for pnpm or yarn) try: Edit React.FC<QueryClientProviderProps>; to React.FC<React.PropsWithChildren<QueryClientProviderProps>>; then patch it $ npx patch-package react-query I'm unsure if there are other components needing similar changes, that was the only component I use from react-query. |
I had the same problem. I was supposed to use react@^17.0.2 for package.json. It is written 17.0.2 in package.json, but if you get a childen type error in QueryClientProvider, please refer to it. |
react-query 3.x only supports React 16.8 || 17.x . You can also see it in package.json. |
This ⬆️ please use v4 beta - the types for I have no plans of changing this for v3 tough, as v3 is not meant to be used with react18. Concurrent features can't work properly without |
@TkDodo Thanks for the clarification. Is v4 stable imminent (coming in the next few days/weeks), or should we expect to wait for a while? |
we don't have any plans to make more breaking api changes. if another api change happens, it will likely not be a big one, and potentially around hydration and SSR, because we haven't fully figured that out. so yes, I'd consider the api stable. regarding the code itself: if no one tries out the beta, whatever we currently have will just become v4.0. So, if you are using react 18.0.0 already, your best bet is to just use v4-beta right now :) |
|
Confirm work on |
basically stable: see TanStack/query#3476 (comment)
why this can not work for me?i added this code to a global DTS file, and the path of module is right. |
Describe the bug
When I do a npm run build, I get a type error.
React.FC should accept children by default. Is it a react error or a react-query bug?
Your minimal, reproducible example
export declare const QueryClientProvider: React.FC;
Steps to reproduce
Upgrade app to react 18, both package and types and do a build.
Expected behavior
Build should compile properly.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Windows 10, node 16
react-query version
3.34.19
TypeScript version
4.6.3
Additional context
No response
The text was updated successfully, but these errors were encountered: