首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用材料设计与打字稿反应

用材料设计与打字稿反应
EN

Stack Overflow用户
提问于 2018-12-09 23:06:37
回答 1查看 232关注 0票数 0

我正在寻找一个模式,使用反应材料设计与打字稿,但我有一些问题。

  1. 导出默认值似乎是一种反模式,而我的tsconfig中的选项将不允许我这样做。我想知道他们是否有更好的方法来做到这一点,而不通过tsconfig禁用它。
  2. 对于使用类而不是函数的状态组件,我将如何将with样式应用到类中。

谁能帮我把anti样式应用到我典型的有状态组件模式,而不引入反模式。

典型状态组件模式:

代码语言:javascript
复制
import * as React from "react";

export namespace Header {
  export interface Props {
  }
}

export class Header extends React.Component<Header.Props> {
  constructor(props: Header.Props, context?: any) {
    super(props, context);
  }

  public render(): JSX.Element {
    return (
      <div> HEADER HTML </div>
    );
  }
}

材料用户界面推荐方法:

代码语言:javascript
复制
import s from './Styleguide.scss';

function Styleguide() {
    ...
}

function LinksComponent() {
    ...
}

function ButtonsComponent() {
    ...
}

const Links = withStyles(s)(LinksComponent);
const Buttons = withStyles(s)(ButtonsComponent);

export {
    Links,
    Buttons
};

export default withStyles(s)(Styleguide);

EN

回答 1

Stack Overflow用户

发布于 2018-12-12 11:40:17

只需将您的样式组件导出为一个命名导出?

代码语言:javascript
复制
import * as React from "react";
import s from './Styleguide.scss';

export namespace Header {
  export interface Props {
  }
}

class BareHeader extends React.Component<Header.Props> {
  constructor(props: Header.Props, context?: any) {
    super(props, context);
  }

  public render(): JSX.Element {
    return (
      <div> HEADER HTML </div>
    );
  }
}

const Header = withStyles(s)(BareHeader);

export { Header };
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53697604

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档