computerjazz / react-native-draggable-flatlist

A drag-and-drop-enabled FlatList for React Native
MIT License
1.93k stars 403 forks source link

TypeError: Cannot read properties of undefined (reading 'map') #502

Open perqa opened 1 year ago

perqa commented 1 year ago

Description

ExceptionsManager.js:151 TypeError: Cannot read properties of undefined (reading 'map')

This error is located at:
    in function DraggableFlatListInner
    in file react-native-draggable-flatlist/src/components/DraggableFlatList.tsx

 const dataRef = useRef(props.data);
  const dataHasChanged =
    dataRef.current.map(keyExtractor).join("") !==
--> props.data.map(keyExtractor).join("");
  dataRef.current = props.data;

To Reproduce Call function DraggableFlatListInner with empty props argument.

Platform & Dependencies Platform: iOS Device: iPhone 12 Simulator

"dependencies": {
    "expo": "~47.0.8",
    "expo-status-bar": "~1.4.2",
    "react": "18.1.0",
    "react-native": "0.70.8",
    "react-native-design-system": "^2.0.3",
    "react-native-draggable-flatlist": "^4.0.0",
    "react-native-gesture-handler": "~2.8.0",
    "react-native-get-random-values": "^1.8.0",
    "react-native-reanimated": "~2.12.0",
    "uuid": "^9.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9"
  },
vinodsnayvik commented 1 year ago

Did you checked that the data you are passing is an array ?

perqa commented 1 year ago

Hi, and thanks for the response. The reason I opened this ticket was just to suggest a more descriptive error message or a more defensive programming strategy. I mean if props.data is empty, it could be flagged, and there is no point in trying props.data.map.