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

87
Views
Changing two states with one button click

I'm new to react and trying to change two states with one button click. Ultimately I want to hide one component and unhide the other when I click a button.

The code works when changing one state, but not with two

import React from 'react'
import Buttons from './Buttons'
import SignUp from './SignUp'
import SignIn from './SignIn'
import { useState } from 'react'

const Intro = () => {

const [showButtons, setShowButtons] = useState(true)

const [showSignIn, setShowSignIn] = useState(false)
const showSignInBtn = () => (showSignIn === false) ? setShowSignIn(true) 
setShowButtons(false) : 
setShowSignIn(false)

const [showSignUp, setShowSignUp] = useState(false)
const showSignUpBtn = () => (showSignUp === false) ? setShowSignUp(true) : 
setShowSignUp(false)




return (
    <div className='introBox'>
        <div className='titleMicroReactor'>
            CARDIFF MICROREACTOR
        </div>
        {showButtons && <Buttons showSignInBtn={showSignInBtn} showSignUpBtn=. 
        {showSignUpBtn}/>}
        {showSignIn && <SignIn />}
        {showSignUp && <SignUp/>}
        
        
        
    </div>
)
}

export default Intro

the showSignIn function is where it goes wrong, thanks in advance

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

0

I think you don't need two states like showSignIn and showSignUp.
Just check with one of them.

For example:

{showSignIn ? <SignIn /> : <SignUp />}

If showSignIn is true show <SignIn /> else show <SignUp />

about 4 years ago · Juan Pablo Isaza Report

0

You can use regular if else

const showSignInBtn = () => {
   if (!showSignIn) {
      setShowSignIn(true)
      setShowButtons(false)
   } else {
      setShowSignIn(false)
   }
}
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!