React does not recognize the `isActive` prop on a DOM element - styled-components

末鹿安然 提交于 2021-02-10 05:10:40

问题


I have the following svg component where I am passing props.

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

I then have a styled-component that looks like this.

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

I am seeing the following react error.

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


回答1:


I ran into the same issue with styled-components and I ended up doing something like this:

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

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


来源:https://stackoverflow.com/questions/58447435/react-does-not-recognize-the-isactive-prop-on-a-dom-element-styled-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!