Encountering an issue where the useMutation function is not recognized on the DecorateProcedure<MutationProcedure> type while attempting to utilize the useMutation feature

Currently, I am utilizing the NextJS app router.

I am attempting to invoke a rather straightforward route:

import { z } from "zod";

import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";

// document sending user email to waitlist database
export const createEmailRouter = createTRPCRouter({
  postEmail: publicProcedure
    .input(
      z.object({
        email: z.string().email(),
      }),
    )
    .mutation(async ({ input }) => {
      console.log("email", input.email);
      return {
        email: input.email,
      };
    }),
});

Then in the root.ts file, I insert the route:

export const appRouter = createTRPCRouter({
  post: postRouter,
  storeEmail: createEmailRouter,
});

However, whenever I attempt to utilize the .useMutation for this route on my page, I continually encounter the following error: https://i.sstatic.net/pxYaL.png

Do you have any ideas on how to resolve this issue? I have been unable to find any relevant information online.

Thank you!

Answer №1

When you import the api, make sure to import it from

~trpc/react

instead of

~trpc/server

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

Conceal the toolbar element if it is not at the top of the page

I am encountering an issue with my toolbar. When I scroll down, the transparent background of the toolbar disappears and it looks like this: . How can I hide this component when the page is scrolled down and show it again when scrolling back up to the top ...

ReactJS issue: Unexpected warning about having a unique "key" prop for each child in a list

What a glorious day! Unfortunately, my view is obstructed by this pesky obstacle: I've exhausted all my options (except asking for help ._.) and scoured every corner. Alas, the desired outcome remains elusive :'( Here's the snippet of code ...

Exploring Heroes in Angular 2: Retrieving Object Information by Clicking on <li> Items

Currently, I am delving into the documentation for an angular 4 project called "Tour of Heroes" which can be found at https://angular.io/docs/ts/latest/tutorial/toh-pt2.html. <li *ngFor="let hero of heroes" (click)="onSelect(hero)">{{hero.name}}< ...

Is the getStaticProps function executed on the server side?

I'm trying to grasp the concept of build time in terms of when it affects the page rendering process versus when it's involved in compiling the app into a Vercel URL. ...

Guide to seamlessly integrating next/font with Tailwind CSS for implementing custom fonts in a Next.js project

I've been working on integrating a custom font using next/font in my Next.js application and configuring it with Tailwind CSS. Despite following the Next.js documentation for next/font, I'm facing issues with getting the font to apply correctly. ...

Exploring Angular 10 Formly: How to Retrieve a Field's Value within a Personalized Formly Wrapper

Utilizing Angular 10, I have a formly-form with a select-field named session. This select field provides options from which to choose a dndSession. Each option holds key-value pairs within an object. I want to add a button next to the select-field that tr ...

jest-dom is ready to go, but @testing-library is searching for the DOM

Following the recommendations on the Next.js site, I set up my testing environment by installing jest, jest-environment-jsdom, @testing-library/react, and @testing-library/jest-dom. Despite this, I am facing difficulties when trying to execute tests that ...

Error encountered when passing props to child components in NextJS

I have a file that defines two types: type IServiceItems = { fields: { name: string; description: string; logo: { fields: { file: { url: string; }; }; }; }; }; type ITechItems = { fields: { n ...

Display the initial MUI components from an array of data in a distinctive manner

Trying to display the content of an Accordion by passing props down through a list array to a component. I have identified the issue but unsure how to call the component and pass the props differently. Below is the code snippet. Code for the parent compon ...

Typesafe-actions for defining typings of async actions reducers

I'm currently facing a minor issue while using createAsyncAction from the library typesafe-actions (Typesafe Actions) and correctly typing them for my reducer function Below is an example of the action being created: export const login = createAsync ...

I am seeking to modify the CSS of the parent component upon the loading of the child component in Angular

In my Angular blog, I have a root component with a navigation bar containing router links to create a single-page application. My goal is to darken the background around the link when the child component loads. Currently, the link highlights only when pres ...

Having trouble locating the .ts module when executing a Node script with experimental modules enabled

I am currently developing a node express project and I need to run a node script from the terminal. Within my project, there are some .ts files that I want to include in the script (MyScript.js). Below is the content of MyScript.js: import get from &apos ...

Error: The specified property is not found in type 'never' - occurring with the ngFor loop variable

When working with API responses and dynamically sorting my view, I utilize an ngFor loop. Here's the snippet of code in question: <agm-marker *ngFor="let httpResponses of response" [latitude]= "httpResponses.lat" [longitude]=& ...

SvelteKit is having trouble with identifying Typescript syntax

I was working on a SvelteKit project with TypeScript (set up with Vite) and everything was running smoothly with "npm run dev". However, when I attempted to publish the app on Github Pages, an error popped up (on localhost) as I hovered over the only link ...

Tips for retrieving items from <ng-template>:

When the loader is set to false, I am trying to access an element by ID that is located inside the <ng-template>. In the subscribe function, after the loader changes to false and my content is rendered, I attempt to access the 'gif-html' el ...

Tips for adding a border to a table cell without disrupting the overall structure of the table

Looking for a way to dynamically apply borders to cells in my ng table without messing up the alignment. I've tried adjusting cell width, but what I really want is to keep the cells' sizes intact while adding an inner border. Here's the sim ...

Unable to simulate a service and retrieve information in an angular unit test - showing as undefined

In my current project, I have a component that I am trying to write unit tests for. However, when I run the test, I noticed that the value of console.log('**fav**' + favorite[`isFavorite`]); shows up as undefined. This indicates that the data I ...

Synchronizing data between parent and child components using two-way binding with emit in Vue 3 using TypeScript

Within my code, there is a child component: <template> <label :class="className + ' ctrl'"> <span><LocCtrl :page="pageName" :locKey="labelLoc" /></span> <input type=&q ...

Navigating with useRouter().push() from the "next/navigation" package is not functioning as expected when used on a customized signIn page alongside next-auth

Upon logging in successfully on my custom signIn-Page using next-auth, I am facing an issue with redirecting back to the callbackUrl. The setup includes react 18.2.0, next 13.4.8-canary.2, and next-auth 4.22.1. The code for the signIn-Page (\src&bsol ...

Set up SystemJS to properly load my Angular 2 component module

Recently, I made the switch from ng1 to ng2. I successfully imported Angular 2 and its modules into my project: <script src="/node_modules/systemjs/dist/system.src.js"></script> <script src="/node_modules/rxjs/bundles/Rx.js"></script& ...