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

147
Views
Variable in the useState not updating in useEffect callback
const Tweet = ({ tweet, checkedList, setCheckedList }) => {
  const [isChecked, setChecked] = useState(false);
  useEffect(() => {
    checkedList === [] && setChecked(false);
  }, [checkedList, isChecked]);
  return (
    <div className="tweet">
      <h3>Name : {tweet.name} </h3>
      <p>{tweet.tweet}</p>
      <input
        type="checkbox"
        checked={isChecked}
        onChange={() => {
          setChecked(!isChecked);
          checkedList.find((e) => e === tweet.id) === undefined
            ? setCheckedList([...checkedList, tweet.id])
            : setCheckedList(checkedList.filter((e) => e !== tweet.id));
        }}
      />
    </div>
  );
}; 

I have a tweet component that has its own state. There is an external checkedList with is basically an array of checked tweet ids. But once I reset the checkedList = [] , I am trying to reset the checked tweets by useEffect. But can't do it. I want all tweets state to be unchecked. What am I doing wrong ?

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

0

checkedList === [] is will never be true .

try to check the length of the checkedList array .

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!