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

267
Vistas
What is the correct syntax for BoxSizing in a React CSS Object

I'm trying to give style to a prop in React but I don't know to correct way to write it :

<PhoneInput
   inputStyle={!(window.innerWidth <= 768) ? {...InputDivStyle, ...PhoneInputStyle, textIndent: "96px"} : {...InputDivStyle, ...PhoneInputStyle, textIndent: "32px"}}
</PhoneInput>

inputStyle gives me the error :

Types of property 'boxSizing' are incompatible. Type 'string' is not assignable to type 'BoxSizing | undefined'.ts(2322)

export const PhoneInputStyle = {
  fontSize: "clamp(13px, 1.111vw, 16px)",
  lineHeight: "clamp(15px, 1.319vw, 19px)",
  position: "relative",
  width: "100%",
  height: "51px",
  cursor: "pointer",
  display: "flex",
  flexDirection: "row",
  alignItems: "center",
  padding: "8px 16px",
  border: `1px solid black`,
  boxSizing: `border-box`, //This ain't right, I tried "border-box" and it didn't work either
  borderRadius: "10px",
  outline: "none",
  gridRowStart: "1",
  gridColumnStart: "1",
}

I'm pretty sure it's only an error of syntax but I can't find the correct way to write boxSizing.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

export const PhoneInputStyle = {
  // ...
  boxSizing: `border-box`,
  // ...
}

Since you don't have an explicit type on this object, typescript will create a type automatically. It sees that boxSizing is a string, so it gives boxSizing the type string. Unfortunately, this is too broad for what you end up doing. box sizing can't be any string, but instead can only be very specific strings.

I would recommend that you give this object an explicit type of CSSProperties. This type will, among other things, restrict boxSizing to its legal values:

import { CSSProperties } from "react";

export const PhoneInputStyle: CSSProperties = {
  // ...
  boxSizing: `border-box`,
  // ...
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

I got the same problem, and I also solved it explicitly giving PhoneInputStyle a CSSProperties type. It worked thanks !

about 4 years ago · Juan Pablo Isaza 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