如果 prop 未定義,我想在 componentDidUpdate 中執(zhí)行一些操作,但是,我不能,因為我剛剛收到錯誤Cannot read property 'serial' of undefined。有辦法解決這個問題嗎?這就是我累的,但它不起作用 - 我收到錯誤:componentDidUpdate(prevProps) { if (typeof this.props.location.state.serial == "undefined"){const database = db.ref().child("Devices/" + prevProps.location.state.serial);...提前致謝!
React:檢查 props 是否未定義
郎朗坤
2023-10-14 19:17:46