React: native img attribute loading="lazy" (chrome new feature).

Created on 28 Sep 2019  路  7Comments  路  Source: facebook/react

attribute loading="lazy" works on image tag as it should;
but in react I should use 'data-loading' or 'custom-loading' otherwise error
Property 'loading' does not exist on type 'DetailedHTMLProps, HTMLImageElement>'
appears.

unfortunately with 'data-loading' or 'custom-loading' not working.

Most helpful comment

@eps1lon as you say, can't accept this since it's not part of the standard yet so is there any other way I can access this feature in "React TypeScript"?

Got you covered: https://react-typescript-cheatsheet.netlify.app/docs/advanced/types_react_api#adding-non-standard-attributes

This was mentioned in the comment I linked.

All 7 comments

Good point, we should add it.

That sounds like a React TypeScript error, can you confirm?

As far as I know, you can already use that property on a img tag.

Property 'loading' does not exist on type 'DetailedHTMLProps'

As @goenning said this is most likely a typescript error. Before you open a PR to @types/react please read https://github.com/DefinitelyTyped/DefinitelyTyped/pull/38694#pullrequestreview-294671505

React doesn't warn against excess props on host components if they're not in camelcase.

As @goenning said this is most likely a typescript error. Before you open a PR to @types/react please read DefinitelyTyped/DefinitelyTyped#38694 (review)

React doesn't warn against excess props on host components if they're not in camelcase.

@goenning & @eps1lon you are right; this is React TypeScript error.
@eps1lon as you say, can't accept this since it's not part of the standard yet so is there any other way I can access this feature in "React TypeScript"?

@eps1lon as you say, can't accept this since it's not part of the standard yet so is there any other way I can access this feature in "React TypeScript"?

Got you covered: https://react-typescript-cheatsheet.netlify.app/docs/advanced/types_react_api#adding-non-standard-attributes

This was mentioned in the comment I linked.

Got you covered: https://github.com/typescript-cheatsheets/react-typescript-cheatsheet/blob/master/ADVANCED.md#adding-non-standard-attributes

This was mentioned in the comment I linked.

thanks.

https://github.com/typescript-cheatsheets/react-typescript-cheatsheet/blob/230fb013f3858ece46f032db62e7af70d9910ffb/docs/advanced/types-react-ap.md#adding-non-standard-attributes
For those looking more recently

// react-unstable-attributes.d.ts
import "react";

declare module "react" {
  interface ImgHTMLAttributes<T> extends HTMLAttributes<T> {
    loading?: "auto" | "eager" | "lazy";
  }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

zpao picture zpao  路  3Comments

Prinzhorn picture Prinzhorn  路  3Comments

huxiaoqi567 picture huxiaoqi567  路  3Comments

framerate picture framerate  路  3Comments

UnbearableBear picture UnbearableBear  路  3Comments