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

224
Views
Renderizar entre el botón de inicio y parada en React Native

Quiero renderizar entre mostrar un botón de inicio y detener basado en presionar los botones. Eso significa que si se presiona el botón de inicio, se debe mostrar el botón de parada y viceversa. En el caso estándar, se debe representar el botón de parada. Con el siguiente código, aparece un error porque el status solo se puede leer, por lo que necesito otra forma de establecer el estado.

 const SampleComponent = () => { const startButton = () => { return <Component1 />; }; const stopButton = () => { return <Component2 />; }; const status = stopButton; return ( <View> <Pressable onPress={() => { if (status == stopButton) { status = startButton; } else { status = stopButton; } }} > {status} </Pressable> </View> ); }; export default SampleComponent;

Necesito una forma de React Native para hacer esto. Traté de estudiar los documentos y también otro material, pero simplemente no lo entiendo.

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

0

La forma de reaccionar de hacer esto sería usar el gancho de estado . Puede usar una variable de estado booleana y alternarla al hacer clic en el botón.

about 4 years ago · Juan Pablo Isaza Report

0

Solución

 const SampleComponent = () => { const StartButton = () => { return <Component1 />; }; const StopButton = () => { return <Component2 />; }; const [status, setStatus] = useState(false); return ( <View> <Pressable onPress={() => { setStatus(!status); }} > {status ? <StopButton /> : <StartButton />} </Pressable> </View> ); }; export default SampleComponent;

Recuerde escribir los componentes en mayúsculas.

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!