Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
¿Cuál es la sintaxis correcta para BoxSizing en un objeto React CSS?

Estoy tratando de darle estilo a un accesorio en React pero no sé cómo escribirlo correctamente:

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

inputStyle me da el 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", }

Estoy bastante seguro de que solo es un error de sintaxis, pero no puedo encontrar la forma correcta de escribir boxSizing.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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

Como no tiene un tipo explícito en este objeto, TypeScript creará un tipo automáticamente. Ve que boxSizing es una cadena, por lo que le da a boxSizing el tipo string . Desafortunadamente, esto es demasiado amplio para lo que terminas haciendo. el tamaño del cuadro no puede ser cualquier cadena, sino que solo puede ser cadenas muy específicas.

Recomendaría que le dé a este objeto un tipo explícito de CSSProperties . Este tipo, entre otras cosas, restringirá boxSizing a sus valores legales:

 import { CSSProperties } from "react"; export const PhoneInputStyle: CSSProperties = { // ... boxSizing: `border-box`, // ... }
about 4 years ago · Juan Pablo Isaza Report

0

Tengo el mismo problema y también lo resolví dando explícitamente a PhoneInputStyle un tipo CSSProperties. Funciono gracias!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!