0

I developed a simple ToDo application using React and Typescript. It works perfectly fine in the development environment and also in the preview version made available by Vite after the build, but when I upload that same application to Vercel, the same crash. After some tests I realized that there is something causing my array of tasks to not really be considered an array.

for example: here I am forced to use Array.from() for the amount of tasks to appear correctly in Vercel.

const tasksQuantity = Array.from(tasksState).length

which leads me to imagine that he is not considering tasksState as an Array

I'm not very experienced with typescript or the use of useReducer, which is why I'm developing this project. I believe that the error may be in my reducer, but I could not solve it

const [tasksState, dispatch] = useReducer(TaskReducer, { tasks: [] }, () => {
    const storedTasks = localStorage.getItem(TASKS_STORAGE_KEY)

    if (storedTasks) {
      return JSON.parse(storedTasks)
    }

    return { tasks: [] }
  })
export interface Task {
  id: number
  content: string
  isDone: boolean
}

I already thank you in advance for any help

KernelDN
  • 17
  • 6
  • The provided code snippets are not sufficient to know where the problem might be. Could you check in the browser devtools what the crash is? Also, where in the code do you save the tasks to localStorage? – Lev Izraelit Jan 13 '23 at 22:27
  • Hi Lev Israel, I managed to solve the problem by replacing `{ tasks: [] }` (when hovering over it it said: tasks: never[ ]) with `[]`. Another point is that my browser (Google Chrome) probably had a "bug", because even after making the corrections listed above, I needed to erase the browsing data for the application to work correctly. (I discovered this by trying to access the domain in Vercel from another device and verifying that everything was normal) – KernelDN Jan 14 '23 at 02:16

0 Answers0