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
method filter infini loop

I have a problem that I can't solve, when I filter I have an infinite loop that starts I don't know why the problem is that when i choose the order of the day option to filter the data keeps loading in the console. Who can explain to me please

const dispatch = useDispatch()
    
    const ifIsCommand = useSelector(state=> state?.reducerCommandAdmin?.state)
    const [listCommand, setListCommand ] = useState([])
    const [ filterDate, setFilterDate ] = useState("all");
    
    useEffect(()=>{
        setListCommand(ifIsCommand)
        getAllCommandAllClientsAdminService(dispatch)
    },[listCommand, filterDate])

    const handleChange = (e) =>{
        setFilterDate(e.target.value)
        
    }
const ResultChoiceDateCommand = () =>{
        if (filterDate === "oldDay") {
            const sortListCommandOld = listCommand?.sort((a, b) => new Date(a.dateDuJour) - new Date(b.dateDuJour))
            return setListCommand(sortListCommandOld)
        }
        if (filterDate === "recentDate") {
       
            const sortListCommandOld = listCommand?.sort((a, b) => new Date(b.dateDuJour) - new Date(a.dateDuJour))
         
            return setListCommand(sortListCommandOld)
        }
        if (filterDate === "dateOfDay") {
            
            if(filterListCommandOfDay.length > 0){
               
                return setListCommand(filterListCommandOfDay)
            }else{
                return <p>no order</p>
            }
   
        }
    }

const year = new Date().getFullYear()
    const day = new Date().getDate()
    const newDay = day < 10 ? "0" + day : day
    const month = new Date().getMonth() + 1
    const newMonth = month < 10 ? "0" + month : month
    const dateOfDay = `${year}-${newMonth}-${newDay}`

const filterListCommandOfDay = listCommand?.filter((dateOfDays) => { 

       if (dateOfDays.dateDuJour === dateOfDay) {
            return dateOfDays.dateDuJour === dateOfDay
        }
    })
about 4 years ago · Santiago Trujillo
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!