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

343
Views
How to resolve loop infinite : Http request inside a loop in React js?

I have a form where in the properties there is a function, in the main I called this form and I have to pass a function that has an array each element of that array I have to call an http request of type PUT and I have an infinite loop problem. have ideas guys??

Form.ts:(it is not complete, I only put the part where the function is)

interface UserFormProps {
    
    selectedUser?: User | null
    formType: string
    onSave: (val: UserFormData) => Promise<boolean>
    onDismiss: () => void
    isVisible: boolean
    GroupFilterSelection?:any
    RoomFilterSelection?:any
    OnAddUser ?:()=>void
}

    <Label >{t('Assegnare Rooms')}</Label>
                {boolean?
                <>
                 <div className="row">
                   <div className="col ">
                     { GroupFilterSelection }
                   </div>
                   </div>
                   <div className="row">
                   <div className="col">
                      { RoomFilterSelection}                 
                   </div>
                
                   <div>
                   <PrimaryButton className="mt-4" onClick={()=>OnAddUser} >{t('Add userRoom')}</PrimaryButton>
                   </div>
                   </div>
                   </>
                 :null
            
                }

Function:

async function AddRoomUser(){
      if(filterrooms&&filterrooms.length>0 && selectedUser){
        
        for await(let i of filterrooms){
           let item : RoomUser = {
           UsersId :selectedUser.UsersId,
           UsersName : selectedUser.User,
           RoomId :i.RoomId
          }
           await dispatch(AddUserRoom(item))
           
        }
        
      }
    }

Main.ts(code html):

<UserForm selectedUser={selectedUser} formType={addOrEditUser} isVisible={displayUserForm} onSave={saveUser} onDismiss={dismissForm} GroupFilterSelection={GroupSelectionFilter} RoomFilterSelection={roomSelectionFilter} OnAddUser={()=>AddRoomUser} ></UserForm>
about 4 years ago · Juan Pablo Isaza
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!