Home > Enterprise >  How to add tabIndex = '0' in TypeScript div?
How to add tabIndex = '0' in TypeScript div?

Time:08-05

I am using Typescript with NextJS, i want to add tabIndex = '0' in one of the div. but am getting this error Type 'string' is not assignable to type 'number'... how to achive this?

‹div className= 'container' tabIndex = '0'>

CodePudding user response:

Instead of tabIndex='0' , you should write it as tabIndex={0}. This way Ty[escript will understand. <div className="container tabIndex={0}>

CodePudding user response:

I think typescript is wrong here, since it ends up as a string in html anyway.

But to please the compiler, pass tabIndex as a JS value like this:

<div className="container tabIndex={0}>
  • Related