反应Material-UI嵌套组件只能用于类组件,而不能用于功能组件

问题描述

我正在尝试在以下行中向NavLink添加样式:

<ListItem button component={Stylednav} to="/transactions">

这有效:

class Stylednav extends React.Component {
  render() {
    const { forwardedRef,...props } = this.props;
    return (
      <NavLink {...props} activeStyle={{ color: "red" }} ref={forwardedRef} />
    );
  }
} 

但这不是:

function Stylednav(props) {
  const { forwardedRef,...props } = props;
  return (
    <NavLink {...props} activeStyle={{ color: "red" }} ref={forwardedRef} />
  );
}

后者给了我错误identifier 'props' has already been declared

为什么会发生这种情况?为了更好地了解JS机制,我需要了解什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)