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

210
Views
El reordenamiento de los elementos de reacción con clave hace que css pase a fallar

Tengo una matriz de 2 elementos con posición absoluta, que están diseñados a través de la propiedad CSS top . Además, hay una transición CSS enganchada a la tecla top . Cuando intercambio posiciones de elementos, algunos elementos (aunque la clave no cambia), el elemento html se vuelve a crear, por lo tanto, la transición de CSS no ocurre.

 import { useEffect, useState } from "react"; import "./styles.css"; const Square = ({ backgroundColor, index }) => { return ( <div className="square" style={{ backgroundColor, top: index * 100 }} /> ); }; export default function App() { const [arr, setArr] = useState(["blue", "red"]); useEffect(() => { setTimeout(() => { setArr(["red", "blue"]); }, 2000); }, []); return ( <div className="App"> {arr.map((backgroundColor, index) => ( <Square index={index} backgroundColor={backgroundColor} key={backgroundColor} /> ))} </div> ); }
 .App { font-family: sans-serif; text-align: center; position: relative; } .square { transition: top 0.5s ease-out; width: 100px; height: 100px; position: absolute; }

He creado un ejemplo de codesandbox del problema: https://codesandbox.io/s/strange-framework-t2rq9

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