Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

89
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda