我试图做类似下面的,但它返回null:您可以使用React Components的es6导入别名语法吗?
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
那么当然,我得到一个多重声明错误。
任何想法?
为什么你不能改变类按钮名称? – Ved
React组件应该以大写字母开头:不使用'styledButton',而是使用'StyledButton' – topheman
@Ved我正在使用react-styleguidist来显示每个组件,并且需要将所有组件包装到组件库中。如果我更改类Button的名称,show code将为操场中的每个组件命名。 –