小编Kos*_*sko的帖子

Material-ui 不会根据主题改变排版颜色

我正在尝试 material-ui,所以我创建了两个主题:

const darkTheme = createMuiTheme({
  palette: {
    type: "dark"
  }
});

const lightTheme = createMuiTheme({
  palette: {
    type: "light"
  }
});
Run Code Online (Sandbox Code Playgroud)

但是当我使用Typography组件时,它的颜色属性不会改变。更重要的是 - 颜色是继承自html所以Typography不知道当前的主题。有没有办法在创建主题或使用默认设置时配置排版颜色?我试图将color道具放在托盘对象中,如下所示:

const darkTheme = createMuiTheme({
  palette: {
    type: "dark"
  }
});

const lightTheme = createMuiTheme({
  palette: {
    type: "light"
  }
});
Run Code Online (Sandbox Code Playgroud)

但没有运气。我已经创建了codepen。在那里我发现,如果我降级material-ui3.1它可以正常工作 -.MuiTypography-body1类设置与主题相对应的颜色属性。

javascript reactjs material-ui

6
推荐指数
1
解决办法
3631
查看次数

如何使用对象传播reduxjs/工具包

我正在尝试将 @reduxjs/toolkit 实现到我的项目中,目前我面临使用扩展运算符的问题

const initialState: AlertState = {
  message: '',
  open: false,
  type: 'success',
};

const alertReducer = createSlice({
  name: 'alert',
  initialState,
  reducers: {
    setAlert(state, action: PayloadAction<Partial<AlertState>>) {
      state = {
        ...state,
        ...action.payload,
      };
    },
  },
});
Run Code Online (Sandbox Code Playgroud)

当我将状态分配给新对象时,我的商店不会更新。但是如果我将减速器更改为代码

state.message = action.payload.message || state.message;
state.open = action.payload.open || state.open;
Run Code Online (Sandbox Code Playgroud)

但这不太方便。那么有没有办法使用扩展运算符呢?

reactjs redux redux-toolkit

6
推荐指数
1
解决办法
2853
查看次数

获取onpopstate事件上弹出的历史记录

我有一个onpopstate事件监听器。我想获得无需穿越历史就弹出的历史记录。我可以这样做history.forward()并获取状态,但这会导致我不想看到的副作用。

window.addEventListener('popstate', (event) => {
    prevHistoryRecord = // How to get it without history.forward()
});
Run Code Online (Sandbox Code Playgroud)

javascript html5-history

5
推荐指数
1
解决办法
1023
查看次数

在 nextjs 应用程序中升级 React 时出现意外令牌错误

我想在 nextjs 应用程序中升级到 React 18。我按照官方文档中的说明进行操作。

npm install next@latest react@latest react-dom@latest

但是当我尝试运行时npm run build出现错误:

/node_modules/next/dist/build/index.js:329
                    ...pageKeys.app ?? [],
                                     ^

SyntaxError: Unexpected token '?'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
Run Code Online (Sandbox Code Playgroud)

我尝试用谷歌搜索这个错误,但没有成功

reactjs next.js

2
推荐指数
1
解决办法
2481
查看次数