我正在学习Astro.我想过在Astro组件中使用MUI的material 组件,如按钮、排版等,因为我已经启用了Reaction集成.

astro.config.js

import { defineConfig } from 'astro/config';
import react from '@astrojs/react';

// https://astro.build/config
export default defineConfig({
    // Enable React to support React JSX components.
    integrations: [react()],
});

Counter.tsx:

import { useState } from "react";
import Container from "@mui/material/Container";
import "./Counter.css";
import { Button, Typography } from "@mui/material";

export default function Counter({
  children,
  count: initialCount
}: {
  children: JSX.Element;
  count: number;
}) {
  const [count, setCount] = useState(initialCount);
  const add = () => setCount((i) => i + 1);
  const subtract = () => setCount((i) => i - 1);

  return (
    <Container>
      <div className="counter">
        <button onClick={subtract}>-</button>
        <Typography variant="h6">{count}</Typography>
        <Button variant="contained" color="secondary" onClick={add}>
          +
        </Button>
      </div>
      <div className="counter-message">{children}</div>
    </Container>
  );
}

在当地,我试着用client:only="react".尽管如此,Astro的风格仍然占据着主导地位.有没有什么正式的/最好的方式,或者至少是一个解决办法,集成MUI和Astro,我错过了,或者只是MUI不能与Astro工作?

提前谢谢你

快速概述的CodeSandBox链接:https://codesandbox.io/s/cranky-ride-3yw946?file=/src/components/Counter.tsx:0-777

推荐答案

正如noktasizi#3070所说,Astro似乎还不支持像MUI这样的UI库(依赖于css-in-Java脚本来实现组件样式).

你可以关注https://github.com/withastro/astro/issues/4432了解更多关于同一主题的信息.

Javascript相关问答推荐

为什么从liveWire info js代码传递数组我出现错误?

Redux工具包查询(RTKQ)端点无效并重新验证多次触发

防止用户在selectizeInput中取消 Select 选项

使用javascript将Plotly Expandable Sparkline转换为HighCharter Plot在bslib卡中

如何在Obsidian dataview中创建进度条

类构造函数不能在没有用With Router包装的情况下调用

VSCode中出现随机行

当标题被点击时,如何使内容出现在另一个div上?

使用线性插值法旋转直线以查看鼠标会导致 skip

Next.js无法从外部本地主机获取图像

无法使用Redux异步函数读取未定义的useEffect钩子的属性';map';

TabNavigator和StackNavigator之间的Reaction Native中的导航问题

在Puppeteer中使用promise进行日志(log)记录时出现TargetCloseError

当达到高度限制时,如何裁剪图像?使用html和css

使用Java脚本在div中创建新的span标记

使用jQuery每隔几秒钟突出显示列表中的不同单词

Rails 7:在不使用导入映射的情况下导入Java脚本

react :图表负片区域不同 colored颜色

用内嵌的含selenium的Java脚本抓取网站

2.0.0-dev quill拖动文本不起作用如何使其拖动文本