Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

121
Vistas
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.

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

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.

over 4 years ago · Santiago Trujillo Denunciar

0

The style prop on regular DOM elements should be in the form of an object where the keys are the css attributes.

Example: <div style={{ width: "100%", backgroundColor: "black" }} />

Notice that in the case of attributes containing dashes, they become camel cased. For instance background-color becomes backgroundColor.

React style documentation

over 4 years ago · Santiago Trujillo Denunciar

0

for me work "import CSS from csstype" && wrap to quotes 'maxHeight': '120px'

import React from 'react';
import CSS from 'csstype';
    
const shortList = () => {
    const listStylus: CSS.Properties = {
        'maxHeight': '120px',
        'overflow': 'hidden',
      }
    
      return (
        <div>
          <ul style={listStylus} >
            <li>Item element 1</li>
            <li>Item element 2</li>
          </ul>
        </div>
      )
}

export default shortList
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda