javascript - React 无法识别 DOM 元素上的 `isActive` 属性 - styled-components

标签 javascript css reactjs ecmascript-6 styled-components

我有以下 svg 组件,我在其中传递 Prop 。

import React from 'react';
export default (props) => (
  <svg {...props}>
    <path
      d="M11.5 16.45l6.364-6.364"
      fillRule="evenodd"
    />
  </svg>
);

然后我有一个看起来像这样的 styled-component

const Icon = styled(_Icon)`
  ${props =>
    props.isActive &&
    css`
      transform: rotate(-180deg);
    `};
`;

我看到以下 react 错误。

Warning: React does not recognize the isActive prop on a DOM element.

最佳答案

我在 styled-components 上遇到了同样的问题,最后我做了这样的事情:

<Icon isactive={isActive.toString()} />

${props =>
  props.isactive === 'true' &&
  css`
    transform: rotate(-180deg);
  `};
}

关于javascript - React 无法识别 DOM 元素上的 `isActive` 属性 - styled-components,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58447435/

相关文章:

html - 调整浏览器窗口大小时使页脚中的内容居中

javascript - 用大对象响应更新状态

javascript - 显示来自 json 的帖子

javascript - 如何使用 javascript 替换 href 链接

javascript - 你能打败破框机吗?

html - 将菜单放在标题中

html - 设置单元格大小不超过一定的宽度和高度

javascript - React Router dom 和 Google webcache 内容 404 错误

reactjs - 如何更改 React-TinyMCE 中的默认语言?

javascript - 如何使用 jsmediatags 从 mp3 获取专辑封面