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

255
Views
Why route parameters mutating in react navigation?

In react native application i am using react navigation. I am send a object from one screen to other. After one section i am running a function which makes copy of my route parameter and modifying the copy. But my original parameter is also modifying. I do not want to modify the original object. How to avoid mutating parameters ?

Here is my parameter structure

{
  id: 1
  name: 'some name',
  productOptions: [
    {
      productOptionId: 1
      productOptionName: 'Option name'
      options: [
        {
          name: 'some option name',
          value: 12
        },
        {
          name: 'some option name',
          value: 12
        },
        {
          name: 'some option name',
          value: 12
        }
      ]
    },
    {
      productOptionId: 1
      productOptionName: 'Option name'
      options: [
        {
          name: 'some option name',
          value: 12
        },
        {
          name: 'some option name',
          value: 12
        },
        {
          name: 'some option name',
          value: 12
        }
      ]
    }
  ]
}

Here is my screen code

const MyScreen({navigation, route}){
   const product = route.params.product
    const productOptions =  route.params.productOptions
  const [newOptionState, setNewOptionState] = useState([])
  useEffect(() => {
      setTimeout(()=>setPreSelected(), 1000)
   }, [])
   
     const setPreSelected = ()=>{
         let tempProductOptions = [...productOptions]
      tempProductOptions.map((item)=>{
         if(item.options.length && item.options.length>1){
             item.options.splice(1)
         }
     })
       setNewOptionState(tempProductOptions)
  }
}

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!