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

191
Views
Disabling the continue button when there is no selection from the table

I have a list from backend. This list is displaying the user's invoices. I want the button to be disabled if the user doesn't select at least one invoice. If the user selects at least 1 invoice, I want the button to be active. But the invoices and the button are in different components.

payment-table.js

Here the IDE warns me like this; 'setEnabledButton' is assigned a value but never used.

  const [selectedItems, setSelectedItems] = useState([]);

  const [enabledButton, setEnabledButton] = useState();

  useEffect(() => {
    if (selectedItems.length > 0) {
      setEnabledButton = true;
    } else {
      setEnabledButton = false;
    }
  }, [selectedItems]);

policy-payment-info.js

<div className={hiddenControlButtonClass}>
  <AS.Button variant="outlined" onClick={handlePayment} enabledButton>
    {t('policy-payment-info.continue')}
  </AS.Button>
</div>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

First set default state for your useState function :

  const [enabledButton, setEnabledButton] = useState(false);

After this you need to execute the seState by add ()

Like this :

 useEffect(() => {
    if (selectedItems.length > 0) {
      setEnabledButton(true);
    } else {
      setEnabledButton(false);
    }
  }, [selectedItems]);

And then, you need to use this state to enable or disable the button :

<div className={hiddenControlButtonClass}>
  <AS.Button variant="outlined" onClick={handlePayment} disabled={enabledButton}>
    {t('policy-payment-info.continue')}
  </AS.Button>
</div>
about 4 years ago · Juan Pablo Isaza Report

0

Your syntax is a little bit off. setEnabledButton is a function that has to be invoked and given the a certain value. Try this:

const [selectedItems, setSelectedItems] = useState([]);

  const [enabledButton, setEnabledButton] = useState(false);

  useEffect(() => {
    if (selectedItems.length > 0) {
      setEnabledButton(true);
    } else {
      setEnabledButton(false);
    }
  }, [selectedItems]);
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!