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

90
Vistas
Change maxWidth only for xxl screens react-table

I am using react-table. In this table I have a column. In that column header and column cell I need to change my maxWidth style property to be 60 for xs to xl and 30 for xxl. Is there a way to do this inline? I would like to only make changes inside this headerProps and cellProps style object rather than creating a seperate file and linking the component to it. Im not the best at scss this project is using scss.

Here is my accessor that has the cellProps and headerProps

  const columns = [
    
    {
        accessor: 'firstName',
        Header: 'First Name',
        Cell: firstNameFormatter
    },
    {
        accessor: 'lastName',
        Header: 'Last Name',
        Cell: lastNameFormatter
    },
    {
        accessor: 'actions',
        Header: <FontAwesomeIcon icon="cog" className="fs-1 ml-2" />,
        headerProps: {
            className: 'bg-light',
            style: {
                maxWidth: 60 <--- make this maxWidth 30 only for xxl screens
            }
        },
        Cell: actionFormatter,
        sticky: 'right',
        cellProps: {
            className: 'bg-light',
            style: {
            maxWidth: 60 <---- make this maxWidth 30 only for xxl screens
            }
        },
    }
  ];

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

0

There is a way, but it's not pretty. Javascript can't use the media queries that CSS offers us, so it must be worked around

Set an event listener on the resize event. On the callback function, set some state value with the computed width of the window. Then set your maxwidth on the cellProps to be this state.

Something like this:

const [maxWidth, setMaxWidth] = useState(getWidth())

function getWidth() {
  const body = document.querySelector("body")
  const width = parseFloat(window.getComputedStyle(body).width)
  if (width > 1200) {
    return 30
  } else {
    return 60
  }
}

window.addEventListener("resize", () => setMaxWidth(getWidth()))

  const columns = [
    
    {
        accessor: 'firstName',
        Header: 'First Name',
        Cell: firstNameFormatter
    },
    {
        accessor: 'lastName',
        Header: 'Last Name',
        Cell: lastNameFormatter
    },
    {
        accessor: 'actions',
        Header: <FontAwesomeIcon icon="cog" className="fs-1 ml-2" />,
        headerProps: {
            className: 'bg-light',
            style: {
                maxWidth: maxWidth
            }
        },
        Cell: actionFormatter,
        sticky: 'right',
        cellProps: {
            className: 'bg-light',
            style: {
            maxWidth: maxWidth
            }
        },
    }
  ];
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