The upcoming router is not compatible with the NextPage type

I am currently working on introducing dynamic routing into an application that was originally designed with static routes. However, I am facing some confusion as I encounter TypeScript errors that are difficult for me to understand. Below is the code snippet where the error occurs, could someone provide guidance on how to resolve this issue?

View the issues I'm experiencing

import { NextPage } from 'next';
import { useRouter } from 'next/router';
// import CardWhitData from 'src/components/molecules/cardWhitData';
import FloatCard from 'src/components/atoms/floatCard';

const Event: NextPage = () => (
  const router = useRouter()
  const {index} = router.query
  <>
    <FloatCard
      mainTitle="This is your event"
      description="This is your description"
    />
  </>
)
export default Event;

Upon running this code, I encounter the following error message:

Type '() => (: any, router: NextRouter | undefined, : any, { index }?: boolean) => any' is not assignable to type 'NextPage<{}, {}>'.
  Type '() => (: any, router: NextRouter | undefined, : any, { index }?: boolean) => any' is not assignable to type 'FunctionComponent<{}> & { getInitialProps?(context: NextPageContext<any>): {} | Promise<{}>; }'.
    Type '() => (: any, router: NextRouter | undefined, : any, { index }?: boolean) => any' is not assignable to type 'FunctionComponent<{}>'.
      Type '(: any, router: NextRouter | undefined, : any, { index }?: boolean) => any' is not assignable to type 'ReactElement<any, any>'.ts(2322)

Answer №1

The curly braces { and } as well as the return statement are missing from the code snippet. The corrected version should look like this:

const Event: NextPage = () => {
  const router = useRouter();
  const {index} = router.query;
  return (
    <>
      <FloatCard
        mainTitle="This is your event"
        description="This is your description"
      />
    </>
  );
}

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

Leverage a nearby module with a local dependency

My current challenge involves integrating a local library into my project. I have been following two tutorials: how to create a library and how to consume a local library. Despite having a well-structured sample library with package.json and index.ts, I am ...

How is it possible for this for loop to function properly without the need to pass the incrementing variable

I managed to compile my code and it's working fine, but there's something interesting - the variable that should reference the incrementing value is not included as an argument in the for loop. var _loop2 = function _loop2() { var p = docume ...

Having trouble importing or resolving files with ts-loader or css-loader?

Struggling to incorporate css modules by utilizing style-loader and css-loader in my project. I am facing difficulties understanding the root cause, unsure if it's ts-loader or css-loader to blame. webpack.config.js const path = require('path&a ...

Encountered a hiccup while trying to send my NextJS app to Verc

Hello everyone, I'm currently facing an issue while attempting to deploy my NEXT-JS App to Vercel. Despite having both the app and pages folders in my project root, I keep encountering the annoying error below. I've tried searching for a solution ...

What is the best way to access automatically generated JavaScript variables in TypeScript?

I am currently facing an issue with integrating a Google login API in my React project and I need some help. The problem arises when the user already has an active session, rendering the API unnecessary. The Javascript solution provided is as follows: co ...

Encountering an error when trying to set data in a Firestore document with a customized JavaScript object: "Invalid data provided for function DocumentReference.set()"

For my initial project, I need help in identifying where the issue lies. Firstly, I have a function that adds data to Firebase: addpost() { let newposts = new Posts( this.addForm.value ) this.postsservice.addPosts(newposts); } Ne ...

Mastering the proper implementation of the factory method in TypeScript

Trying to articulate this question is proving to be a challenge, but I'll give it my best shot. In Sharepoint, a default ListItem comes with properties like id, title, createdby, createddate, modifiedby, and modifieddate. Custom lists can have addit ...

Dealing with Nginx and Next.js when encountering a 404 error on static files

I currently have a WordPress site hosted in the /var/www/html/ path with an nginx server. However, I am looking to integrate a specific page using nextjs (also in the /var/www/html/ path) through proxy on port 3000. When I try to access example.com/specifi ...

Typescript allows you to apply a filter to an array

Query: Is there a way to display a pre-selected item from my dropdown using its unique ID? Issue/Explanation: The dropdown options in my web service are dynamically fetched based on a user's ZipCode. For example, a Provider is displayed as {Pho ...

Using TypeScript to create a unique object type that is mapped with generics for each key

Suppose I have a type representing an array of two items: a list of parameters and a function with arguments corresponding to the parameters. I've created a handy function to infer the generic type for easy use. type MapParamsToFunction<A extends a ...

What is the best way to first identify and listen for changes in a form

In Angular, there are reactive forms that allow you to track changes in both the complete form and specific fields: this.filterForm.valueChanges.subscribe(() => { }); this.filterForm.controls["name"].valueChanges.subscribe(selectedValue => { }); ...

Using JWT for Conditional Rendering in Next JS

My component setup looks like this: export default function Header () => { return ( <button> FIRST BUTTON </button> <button> OTHER BUTTON </button> ) } My goal is to display the first button if the user is not connected, and ...

Issue concerning the Bootstrap version, transitioning from Bootstrap 3 to Bootstrap 4

Upon initially installing bootstrap version "bootstrap": "^3.3.7",, everything was functioning properly, except for the inability to utilize a card component. For example: <div class="card" style="width: 18rem;"> <img class="card-img-top" src= ...

Why does the warning in `middleware.ts` still linger even after Clerk has been removed?

After removing the "Clerk" installation from my project and deploying it to production, I encountered an error that is preventing me from going live. Despite not finding any references to Clerk in my app, I am still facing this issue. Can anyone assist me ...

React is not displaying the most recent value

During the initial rendering, I start with an empty array for the object date. After trying to retrieve data from an influxDB, React does not re-render to reflect the obtained results. The get function is being called within the useEffect hook (as shown in ...

Tips for utilizing the "this" keyword in TypeScript

As a newcomer to TypeScript, I am seeking assistance on how to access the login service within the authenticate function. Despite using the 'this' keyword to retrieve the login service, it seems ineffective. Additionally, I find myself puzzled by ...

Insert analytics code post-button click permission granted in Next.js/React

Need help with activating analytics scripts upon a button click? I have analytics scripts that I want to add to my next.js website only if the user opts in. When a button in my CookieBanner component is clicked, a cookie is set to track if the user has o ...

Restricting a checkbox to a maximum of 5 checkmarks

In a multi-column table, each column is represented by a checkmark. I want to limit the ability to tick a checkmark to only 5 checkmarks. Here is the code that has been implemented: <tbody> <ng-container *ngFor="let col of testData" ...

Cannot assign a string literal type in TypeScript to a type parameter that is extending a string literal type

Here is some code snippet that exhibits a specific issue: type FooType = 'Bar'; abstract class Meow<T extends FooType> { baz: T = 'Bar'; } An error is triggered stating Type '"Bar"' is not assignable to type 'T ...

The getStaticProps() function in NextJS has not been invoked

Currently, I am working on a basic website and my goal is to retrieve data from an API and showcase it on my component. However, I've encountered an issue where the getStaticProps() method doesn't seem to be triggering. Below is the code snippet ...