Navigating a text input field in a NextJS application

Having trouble with handling input from a textarea component in a NextJS app.

This is the structure of the component:

<textarea placeholder={pcHld}
          value={fldNm}
          onChange={onChangeVar}
          className="bg-cyan-300"
          rows={3} cols={20} />

The issue lies within the onChange function.

Here's how the onChangeVar function is defined:

  const onChangeVar = (event: FormEventHandler<HTMLTextAreaElement>):
    void => {
      console.log('onChangeVar:'+event.name)
      console.log('onChangeVar(JSOD):'+JSON.stringify(event))
  };

Currently, only debugging messages are being displayed. The main objective is to retrieve the text content from the textarea and utilize it accordingly.

Encountering the following error:

Type '(event: FormEventHandler<HTMLTextAreaElement>) => void' is not assignable to type     'ChangeEventHandler<HTMLTextAreaElement>'.
  Types of parameters 'event' and 'event' are incompatible.
    Type 'ChangeEvent<HTMLTextAreaElement>' is not assignable to type     'FormEventHandler<HTMLTextAreaElement>'.
      Type 'ChangeEvent<HTMLTextAreaElement>' provides no match for the signature '(event:    FormEvent<HTMLTextAreaElement>): void'.ts(2322)
......

or:

Type '(event: ChangeEventHandler<HTMLTextAreaElement>) => void' is not assignable to type 'ChangeEventHandler<HTMLTextAreaElement>'.
  Types of parameters 'event' and 'event' are incompatible.
    Type 'ChangeEvent<HTMLTextAreaElement>' is not assignable to type 'ChangeEventHandler<HTMLTextAreaElement>'.
      Type 'ChangeEvent<HTMLTextAreaElement>' provides no match for the signature '(event: ChangeEvent<HTMLTextAreaElement>): void'.

Seems like there's an issue with the code due to conflicting types.

Tried some solutions without success. Any suggestions on how to modify the code to resolve this problem?

Answer №1

Revise this line

const onChangeVar = (event: FormEventHandler<HTMLTextAreaElement>):

Change it to

const onChangeVar = (event: ChangeEvent<HTMLTextAreaElement>):

While ChangeEvent pertains to the event object itself, FormEventHandler is related to the function.

const onChange: FormEventHandler<HTMLTextAreaElement> = (event) => {}
const onChange = (event: ChangeEvent<HTMLTextAreaElement>) => {}

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

Encountering an error while unit testing Angular components with MatDialog: "Error: <spyOn>: open has already been spied upon."

Once I create an HTML file with a button, I trigger a poll to appear after an onClick event. Then, when the "submit" button is clicked on the dialog window, it closes and I intend to execute subsequent methods. In my TypeScript file: openDialogWindow() { ...

Error encountered in NextJS: Styles written in SASS do not take effect on AMP pages

Why are SASS styles not being applied to AMP pages, but functioning properly on normal webpages? The nextjs docs do not provide any guidance on using SASS styles for AMP pages. Do we need to configure next.config.js? import React from "react"; im ...

What could be causing the issue with my React Native app's release version not opening on a physical Android device?

I encountered an issue while trying to install the Release version of my application. In order to test both the debug and release versions on my physical and virtual devices, I utilized the following commands: ./gradlew assembleDebug, ./gradlew assembleRel ...

The utilization of media within the meta in Next.js is not allowed

Recently, I came across an interesting article about PWAs on web.dev. The article discusses color schemes and at one point, they talk about it in detail, I'm currently working with Next.js and decided to try implementing the following code snippet: & ...

Utilizing useLocation for Defining Text Styles

I'm currently integrating TypeScript into my project, but I'm encountering an error related to 'useLocation' in my IDE. Any thoughts on what might be causing this issue? import React from "react"; import { useHistory, useLocat ...

Having difficulty retrieving an angular file from a location outside of the asset folder

I'm encountering issues with a small project that is meant to read a log and present it in table format. Here is the outline of the project structure: project structure Within the LOG directory, I should be able to access motore.log from my DataServi ...

Node.js app hosted on Azure Functions unable to resolve NPM dependencies

I set up a Node (TypeScript) Azure Function application using the VSCode Azure Function extension. While checking the deployment output, I noticed the following log line: Started postDeployTask "npm install (functions)". Despite this, I couldn&a ...

I am puzzled as to why I keep receiving the error message "Cannot read property 'poPanel' of undefined"

CSS In my project, I am implementing a feature that displays an ordered list by looping through an array of objects and adding them on a button click. It works smoothly for adding items, but when I try to implement a remove function to delete each item, I ...

Error message: "Encountered an issue where the property 'dispatch' is unreadable due to being undefined

I'm facing an issue with the dispatch function as it seems to be unreadable. My goal is to extract data from the store.js file and display it in index.js. I am currently exploring Redux for my web project which involves handling large amounts of data. ...

Troubleshooting Subpabase (Next.js) queries on multi-level/relational tables that result in returning null values

Currently, I am working with three tables in my database setup: 1->profiles (auth.id (FK from auth.user table), username, useremail) 2->posts (post_id, user_id (FK from profile table, post_text)) 3->post_replies(reply_id, user_id (FK from profile ...

The upcoming deployment encounters issues specifically with Amplify

I have been attempting to deploy my Next.js app on AWS Amplify, but unfortunately, it keeps failing. The build process worked flawlessly in my local environment, and I was even successful in deploying it on Vercel. However, for some reason, it only fai ...

Using Next.js for dynamic routing with JSON arrays in getStaticPaths

I am currently facing an issue while trying to incorporate a json file with multiple arrays into my Next.js application. The structure of the json file is quite complex, and I'm unsure about how to convert it into a format that can be effectively util ...

Typescript Error: lib.d.ts file not found

Recently, I experimented with Typescript and utilized the Set data structure in this manner: var myset = new Set<string>(); I was pleasantly surprised that there was no need for additional libraries in Typescript, and the code worked smoothly. Howe ...

Prisma is continuously spitting out data beyond my jurisdiction

I'm currently working on a project that involves postgreSQL and Prisma. While debugging in getServerSideProps(), I noticed that Prisma is automatically console.logging long strings like the following: prisma:query SELECT "public"."TaskC ...

Error: The specified type 'OmitWithTag<GetServerSidePropsContext<ParsedUrlQuery>, keyof PageProps, "default">' does not meet the requirements of '{ [x: string]: never; }'

While my app works in dev mode, it crashes when I try to run the build command. The output of npm run build is as follows: > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b5dbd0cdc198d4c5c598c1d0d8c5d9d4c1d0f5859b859b84"&g ...

The autocomplete feature in Atom is not functioning as expected

Autocomplete+ is included with the installation of Atom and is activated by default. I have noticed that when I am coding, no suggestions are appearing. What could be causing this issue? Do I need to adjust any files in order for Autocomplete+ to functio ...

Mastering the utilization of license keys in react-froala within the Next.js framework

I am currently utilizing the "react-froala-wysiwyg": "^2.9.1-1" alongside version "next": "^7.0.2". Having obtained a license and generated a key specific to my domain, I find myself unsure of how to properly integrate it. Despite my attempts to implemen ...

Creating TypeScript atom packages

Has anyone successfully implemented this before? I couldn't locate any assistance for it. If someone could provide references to documentation or existing code, that would be great. I know that Atom runs on Node and that there is a TypeScript compil ...

Ways to implement material-ui button design on an HTML-native button

I am using pure-react-carousel which provides me an unstyled HTML button (ButtonBack). I would like to customize its style using material-ui. Trying to nest buttons within buttons is considered not allowed. An approach that works is manually assigning th ...

How does Typescript handle dependency injection compared to the JSDoc typedef module import for defining types?

Currently, I am facing an issue with defining dependency injection in Typescript. In my experience with JSDoc, I have used typedef import('./classModule.js').default myClass. To illustrate, let's consider multiple classes stored in their o ...