0

I created the following useToggle hook which does not make use of .map():

import { useState } from "react";

export const useToggle = (
  initialValue: boolean = false
): [boolean, () => void] => {
  const [value, setValue] = useState(initialValue);

  const toggleValue = () => setValue((prevVal) => !prevVal);

  return [value, toggleValue];
};

The TS compiler gives me the following error:

./src/Components/util/hooks/useToggle.ts
  Line 0:  Parsing error: Cannot read property 'map' of undefined

I've searched for the word map in the file like 10 times, but it's not there. Someone please reassure me I'm not going insane!

  • Does this answer your question? [Line 0: Parsing error: Cannot read property 'map' of undefined](https://stackoverflow.com/questions/62079477/line-0-parsing-error-cannot-read-property-map-of-undefined) – A_A Jan 13 '21 at 22:14
  • The solution was to reinstall `node_modules` – Ludwig Nagelhus Jan 13 '21 at 22:16

1 Answers1

0

The solution was simpler than I imagined:

Step 1: delete node_modules

Step 2: npm install

Step 3: error gone