Issue: tanstack_react_query's useQuery function is not recognized

Error: (0 , tanstack_react_query__WEBPACK_IMPORTED_MODULE_3_.useQuery) is not a function

While implementing data fetching in my Next.js project using @tanstack/react-query, I encountered the above error message.

Below is the code snippet where the issue occurs:

Shown below is the component responsible for fetching and displaying the data.

import React from 'react'
import ServiceProps from '../interfaces/ServiceProps'
import { fetchServices } from '../api/services/api'
import { useQuery } from "@tanstack/react-query";

const Service = ({ title, content }: ServiceProps) => {
    const { data, isLoading, isError, error, } = useQuery({ queryKey: ["fetchServices"], queryFn: fetchServices });
    console.log(data)
    return (

        <div className="dark:bg-transparent rounded-lg  dark:border-[#212425] dark:border-2 bg-blue-50 p-8">
            {/* <img alt="icon" srcset="/images/icons/icon-1.svg 1x, /images/icons/icon-1.svg 2x" src="/images/icons/icon-1.svg" width="40" height="40" decoding="async" data-nimg="1" className="w-10 h-10 object-contain block" loading="lazy" /> */}
            <div className="space-y-2 break-all">
                <h3 className="dark:text-white text-xl font-semibold">
                    {title}
                </h3>
                <p className=" leading-8 text-gray-lite dark:text-[#A6A6A6]">
                    {content}
                </p>
            </div>
        </div>


    )
}

export default Service

//Here is my API call using Axios

import axios from "axios";

export const fetchServices = async () => {
    const response = await axios.get(`api/services`);
    return response.data;
};

Answer №1

Make sure to include "use client"; at the beginning of your Server page for proper functionality.

If you are working with SSR, refer to the official documentation provided by Tanstack for more in-depth information: The documentation outlines two different approaches to implementation using either Page or App Router.

Answer №2

In order to utilize the QueryClientProvider, it is essential that it is applied within components designed for clients. For a comprehensive guide, refer to this resource: Implementing React Query in Next.js

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the Best Way to Toggle the Visibility of Specific Buttons in a Table Using Jquery?

<html> <head> <script> $( "#clickMeButton" ).click(function() { $(this).next("#hiddenButton").slideToggle( "slow", function() { // Animation complete. }); }); </script> </head> <body> <table> <tr& ...

Is it possible in Angular to generate a module and component without including a CSS file in a single command?

Is it possible to generate a Module linked to a component without automatically creating a css file? For example, the default method I've been using involves: ng generate module name / ng generate component name This results in the typical componen ...

What is the best method for effectively organizing and storing DOM elements alongside their related objects?

In order to efficiently handle key input events for multiple textareas on the page, I have decided to create a TextareaState object to cache information related to each textarea. This includes data such as whether changes have been made and the previous co ...

Utilizing the `promise.all` object in a useState hook

Can anyone help me with setting up an object to use useState? I am working with the dataMap object that needs to be passed to the setResults function. Any assistance would be greatly appreciated! ? export default function Home() { const [results, setRe ...

What could be causing my HTML source code to display incorrectly when using getStaticProps and getServerSideProps?

Encountering issues with the HTML rendering of a page using getStaticProps or getServerSideProps. No content related to the <head> element or main content like <h1> and <p> tags. For example: Visit this link => When inspecting the pa ...

Switch the style sheets after the content

How can I create a toggle effect on the :after property, switching between + and - each time the link is clicked? I've attempted to achieve this using JavaScript, CSS, and HTML, but the code only changes + to - and doesn't switch back when the l ...

Using the 'type' field as a parameter in a Vue2 component object

I need help with passing an object into my component. Here is a snippet of the object's properties: { title: "myTitle", type: "myType" } However, when I define the prop in my component like this, I get a Vue runtime warning st ...

Having trouble adding a test card to the Google Pay testing environment and calculating the order total

How can I display the order total in GooglePay payment sheet? I could not find any documentation on this. Is it possible to do so? Even though I am using the TEST environment, I am unable to add any test card as mentioned in the URL provided below. Additio ...

Facebook has broadened the scope of permissions for canvas applications

I am in the process of developing a Facebook canvas application that requires extended permissions for managing images (creating galleries and uploading images) as well as posting to a user's news feed. I am currently facing challenges with obtaining ...

A small computation

How can I modify this code to calculate the total price #ttc by multiplying #totalcout with #marge Currently, I am able to add amounts when checkboxes are clicked, but I am struggling with integrating the multiplication for calculating the Total Price (TT ...

Facing issues with nodemailer in Nextjs application

After following a tutorial on building a simple mailing app using Next.js and Nodemailer from a YouTube video, I encountered errors that I'm unsure how to troubleshoot. Below is the code I used, any advice on resolving these issues would be greatly ap ...

Is it possible to load a script dynamically in nextjs _app.js before any other scripts?

I need help with implementing the OneTrust CMP solution for my Next.js project on a specific domain. I have set up the script to load before any other scripts in the _app.js file, and I want to prevent it from loading if the sub-domain is 'X'. De ...

Using jQuery's .each() method to iterate over a JSON object may only display the

Running into some trouble with jQuery.each(). I'm pulling JSON data from another PHP file and trying to display a specific key value from it. This is the JavaScript code I have: <div class="row" id="fetchmember"> <script type="text/javasc ...

Is there a harmonious relationship between next.js and mongodb?

I searched extensively for a solution to my issue but still haven't found a clear answer. When working with MongoDB, it's common practice to establish a connection and then close it after completing the task. However, in environments like next.js ...

Utilizing Ajax for dynamic PHP result determination

HTML CODE <div class="card text-center pricing-card mb-20"> <ul class="list-group list-group-flush"> <?php $gbewas = mysqli_query($con,"SELECT * FROM price"); while($okks = mysqli_fetch_array($gbewas)) { ?> <li cla ...

Scrollbar width does not expand when hovered over

I am having trouble increasing the width of the scrollbar when hovering over it. However, I keep receiving an error in the console stating that 'scrollbar.addEventListener' is not a function. JAVASCRIPT setTimeout(function() { const scrollbar ...

How to resolve hydration error in Next.js: Issue - Server-rendered HTML content does not match the text content

What should be done when the client has additional or different information than the server? For example, reading data from localStorage and displaying it. The content is different, so why does this hydration error occur? Error: Text content does not matc ...

The reducer I have is inexplicably returning undefined even though I'm certain it was added to combineReducers

After countless hours of debugging, everything seems to be in working order but the problem still persists. The main reducer file is located at reducers/index.js // @flow import { combineReducers } from "redux"; import blocks from "./blocks"; import user ...

Filtering JSON Objects in JavaScript: A Comprehensive Guide

I have been attempting to filter the JSON object below and create an array of objects that have a value containing "steve" in the key 'markdown'. My initial approach involves converting the object to an array then applying a filter. Although I h ...

Display an array containing date objects in a dropdown menu for users to select from

I am working with an API call that returns an array of objects. Each object in the array contains a date or timestamp in ISO format. Right after my render() method, I have the following code snippet: const pickerItems = this.props.currentData.trips.map(t ...