Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type for style attribute passed to function

Please consider this typescript function

 function button(style: any, func: ()=>void, img: string) {     return (       <button         className="Reader_Button"         style={style}         onClick={func}       >         <img src={img} alt="" />         Back       </button>     );   } 

What is the correct type for the first argument style? I feel like it should be something like HTMLElementStyle but I can't find the right incantation.

Sorry, I wasn't sufficiently clear. I want to know what type to use to replace the "any" in style: any. The typescript definitions handle checking the types of the supplied members of the object.

I'm talking about definition of the function, not application.

like image 969
GaryBishop Avatar asked Jul 10 '17 19:07

GaryBishop


People also ask

How do you pass styles as props react TypeScript?

Use the React. CSSProperties type to pass CSS styles as props in React TypeScript, e.g. style: React. CSSProperties; . The CSSProperties type is used to type the style object that consists of CSS property names and values.


1 Answers

The type is React.CSSProperties. You can find this in VSCode by writing <div style={{}}> and pressing F12 when having your cursor in the style attribute.

like image 55
Dan Homola Avatar answered Sep 29 '22 13:09

Dan Homola