React 包装器:React 无法识别 DOM 元素上的 `staticContext` 属性 [英] React wrapper: React does not recognize the `staticContext` prop on a DOM element

查看:136
本文介绍了React 包装器:React 无法识别 DOM 元素上的 `staticContext` 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试围绕 react-router-dom NavLink 组件创建一个包装器组件.

I'm trying to create a wrapper component around the react-router-dom NavLink component.

我希望我的自定义组件接受所有 NavLinks 道具,并将它们代理到 NavLink.

I would like my custom component to accept all of NavLinks props, and proxy them down to NavLink.

但是,当我这样做时,我得到:

However when I do this, I'm getting:

警告:React 无法识别 DOM 上的 staticContext 属性元素.如果您有意希望它作为自定义出现在 DOM 中属性,将其拼写为小写 staticcontext.如果你不小心从父组件传递了它,将它从 DOM 中删除元素.

Warning: React does not recognize the staticContext prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase staticcontext instead. If you accidentally passed it from a parent component, remove it from the DOM element.

可以在此处找到该问题的工作演示:

A working demo of the issue can be found here:

推荐答案

有一种克服的方法是使用:

There is a way to overcome that is using:

const { to, staticContext, ...rest } = this.props;

所以你的 ...rest 永远不会包含 staticContext

So your ...rest will never contain staticContext

这篇关于React 包装器:React 无法识别 DOM 元素上的 `staticContext` 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆