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

175
Views
2 questions.. first is i want the text to change in condition and the other is the button cant be click if meet the condition

this is the sample code of what I'm trying to do.. on the condition "detailProduct.stock == 0". I want it to change the text if the condition is met. but the thing is only "Equipment Available" appears and "Out of Stock" never appears.. also my button. "Buy Now" I want it to be disabled if the stock = 0 like what I want in my first question. It's kind of hard to find and experiment with some syntax so ill ask here thanks!

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

0

Are you sure the value of detailProduct.stock is zero?

for button instead of using the Link element , try to use button itself and in the onClick event use navigate from react-router-dom

function TestElement(){
    const navigate = useNavigate()
    const [detailProduct, setDetailProduct] = useState({stock: 0})
    const handleClick=()=>{
        // handle your logic
        navigate('/cart') // react-router-dom v6
    
    }
    
    return(
        <div>
            <button onClick={handleClick} disabled={detailProduct.stock === 0}>
                Buy Now
            </button>
        </div>
    )
}
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!