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

120
Views
Storing data across nextjs pages

I'm building a react app with next and I'd like to store some data to be accessed on another page. I followed this guide on the creating a useLocalStorage hook however I keep getting an error NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.

I have this function:

function useLocalStorage(key, value) {
  const [storedValue, setStoredValue] = useState(() => {
    if(typeof window !== "undefined"){
      const item = window.localStorage.getItem(key)
      return item ? JSON.parse(item) : value;
    }
  })

  const setValue = (value) => {
    useEffect(()=>{
      const valueToStore = value instanceof Function ? value(storedValue) : value
      
      setStoredValue(valueToStore)
      
      if(typeof window !== "undefined"){
        window.localStorage.setItem(key, JSON.stringify(valueToStore))
      }
    },[])
  }

  return [storedValue, setValue]
}

and then

const [data, setData] = useLocalStorage("data", props)

with setData called from a button which goes to the next page

any help/criticism is greatly appreciated and if there is a simpler/better way to do this that would be amazing.

Thanks!

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!