TypeErrorCannot destructure property 'name' of 'null' as it is null.
يعني ايه
فكّكت خاصية من null أو undefined. التفكيك محتاج object موجود.
ليه بيحصل
- function بتفكّك الـparameter بتاعها وناداها حد من غير argument.
- داتا (API أو JSON) رجّعت null.
إزاي تصلّحه
- حط قيمة افتراضية للـparameter كله:
({ id } = {}). - افحص الداتا قبل التفكيك. (القيمة الافتراضية جوه الأقواس بتشتغل مع undefined بس، مش مع null.)
جرّبناه فعلًا
const { name } = null;function show({ id } = {}) { return id; }
console.log(show());
const { name } = { name: 'نور' };
console.log(name);undefined
نور