简体   繁体   中英

How to add tabIndex = '0' in TypeScript div?

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'>

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}>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM