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

185
Views
Removing an specific item from a map

i have this code that i'm using to store some data into firebase. The code is working fine but i wanted to add an option that each time someone adds a new field, then them have the option to delete it in case it's not needed. However, i can't come up with a solution to this problem, because the function i've made deletes all the fields, not just the one clicked. Any help?

Here's the code

const handleSubmit = e => {
    e.preventDefault()

    if(
      !form.steps
    ){
      alert("Please fill out the fields!")
      return
    }
    addDoc(recipesCollectionRef, form)
    setForm({
      steps: []
    })
    setPopupActive(false)
  }

      const handleStep = (e, i) => {
        const stepsClone = [...form.steps]
        stepsClone[i] = e.target.value
        setForm({
          ...form,
          steps: stepsClone
        })
      }
      const handleStepCount = () => {
        setForm({
          ...form,
          steps: [...form.steps, ""]
        })
      }
      const handleStepBack = (e, i) => { //the one i'm having problem with
        const stepsClone = [...form.steps]
        stepsClone[i] = e.target.value
        setForm({
          ...form,
          steps: [...form.steps[i]]
        })
      }
              {popupActive && <div className="popup">
            <div className="popup-inner">
              <h2>Add a new recipe</h2>
              <form onSubmit={handleSubmit}>
                <div className="form-group">
                  <label>Steps</label>
                  {
                    form.steps.map((step, i) => (
                      <>
                      <textarea type="text" key={i} value={step} onChange={e => handleStep(e, i)}/>
                      <button onClick={e => handleStepBack(e, i)}>Remove Step</button>
                      </>
    
                    ))
                  }
                  <button type="button" onClick={handleStepCount}>Add Step</button>
                </div>
                <div className="buttons">
                  <button type="submit">Submit</button>
                  <button type="button" class="remove" className="remove" onClick={() => setPopupActive(false)}>Close</button>
                </div>
              </form>
            </div>
          </div>}
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!