【发布时间】:2025-12-22 05:40:06
【问题描述】:
我正在尝试执行以下操作,但是它返回 null:
import { Button as styledButton } from 'component-library'
然后尝试将其呈现为:
import React, { PropTypes } from "react";
import cx from 'classNames';
import { Button as styledButton } from 'component-library';
export default class Button extends React.Component {
constructor(props){
super(props)
}
render() {
return (
<styledButton {...this.props}></styledButton>
)
}
}
原因是,我需要从库中导入Button 组件,还需要导出一个同名但保留导入组件功能的包装器组件。如果我把它留在import { Button } from component library 那么当然,我会得到一个多重声明错误。
有什么想法吗?
【问题讨论】:
-
为什么不能更改类按钮名称?
-
React 组件应该以大写字母开头:不要使用
styledButton,而是使用StyledButton -
@Ved 我正在使用 react-styleguidist 显示每个组件,并且需要将所有组件包装在组件库中。如果我更改类 Button 名称,
show code将为操场中的每个组件具有不同的名称。 -
正如@topheman 所说,别名应该是pascal 大小写-->AliasName
标签: javascript reactjs import ecmascript-6 ecmascript-2016