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

279
Views
Reaccionar: ¿Cómo animar el cambio del componente renderizado?

Cambio el componente que se representa a través de un intervalo de tiempo.

Me gustaría poder agregar una animación cada vez que ocurra ese cambio. ¿Cuál es la mejor manera de hacerlo?

 constructor (props) { super(props) this.state = { currentComponent: 1, numberOfComponents: 2} } componentWillMount() { setInterval(() => { if(this.state.currentComponent === 2) { this.setState({currentComponent: 1}) } else { this.setState({currentComponent: this.state.currentComponent + 1}) } }, 5000) } render(){ let currentComponent = null; if(this.state.currentComponent === 1) { currentComponent = <ComponentOne/>; } else { currentComponent = <ComponentTwo/>; } return( currentComponent ) }

EDITAR:

Además, cuando intento usar 'react-addons-css-transition-group', aparece el siguiente error:

ingrese la descripción de la imagen aquí

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede hacerlo con ReactCSSTransitionGroup como se indica en esta sección

tu CSS:

 .example-enter { opacity: 0.01; } .example-enter.example-enter-active { opacity: 1; transition: opacity 500ms ease-in; } .example-leave { opacity: 1; } .example-leave.example-leave-active { opacity: 0.01; transition: opacity 300ms ease-in; }

Se verá así:

 import ReactCSSTransitionGroup from 'react-addons-css-transition-group'; class MyComponent extends Component { constructor (props) { super(props) this.state = { currentComponent: 1, numberOfComponents: 2} } componentWillMount() { setInterval(() => { if(this.state.currentComponent === 2) { this.setState({currentComponent: 1}) } else { this.setState({currentComponent: this.state.currentComponent + 1}) } }, 5000) } render(){ let currentComponent = null; if(this.state.currentComponent === 1) { currentComponent = <ComponentOne/>; } else { currentComponent = <ComponentTwo/>; } return( <ReactCSSTransitionGroup transitionName="example" transitionEnterTimeout={500} transitionLeaveTimeout={300}> {currentComponent} </ReactCSSTransitionGroup> ) } }
over 4 years ago · Santiago Trujillo 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!