【问题标题】:Cannot read properties of undefined ('reading params')无法读取未定义的属性(“读取参数”)
【发布时间】:2022-01-08 14:46:56
【问题描述】:

谁能帮我解决我的错误 这是我的代码:

const ProductScreen = ({match, history}) => {
    const [qty, setQty] = useState(1);
    const dispatch = useDispatch();
    
    const productDetails = useSelector((state) => state.getProductDetails);
    const { loading, error, product } = productDetails;

    useEffect(() => {
        if (product && match.params.id !== product._id){
            dispatch(getProductDetails(match.params.id));
        }
    }, [dispatch, product, match]);

if 语句出现错误。提前感谢您的帮助!

error

【问题讨论】:

  • 错误信息有什么不清楚的地方?你做了什么调试?
  • 可以查看传递的match

标签: javascript reactjs


【解决方案1】:

您正在为 match 变量传递 undefined(或不传递任何内容)。检查引用它的代码这个组件,并确保它总是传递一个名为 match 的道具。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-19
    • 2020-06-20
    • 2023-03-11
    • 2022-01-15
    • 2021-12-31
    • 2021-12-13
    • 2021-11-28
    • 2021-11-15
    相关资源
    最近更新 更多