控制台报错it looks like an unknown prop “***“ is being sent through to the DOM

自定义组件传输变量时报警告

it looks like an unknown prop “***” is being sent through to the DOM, which will likely trigger a React console error. If you would like automatic filtering of unknown props, you can opt-into that behavior via <StyleSheetManager shouldForwardProp={...}> (connect an API like @emotion/is-prop-valid) or consider using transient props ($ prefix for automatic filtering.)

在这里插入图片描述

意思是我们向DOM传输了一个未知的prop变量,触发了React的警告,想要消除警告我们可以安装类似于@emotion/is-prop-valid的插件或者在传入的变量前加$符号,我这里采用加$符号解决(注意从props取值时也要加$

改之前

  • 传入
    在这里插入图片描述
  • 使用
    在这里插入图片描述

改之后

  • 传入
    在这里插入图片描述
  • 使用
    在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42560424/article/details/133015413