React 的 Material-UI 文档说主要和次要颜色的明暗变体将自动计算。
(来自文档:https : //material-ui.com/customization/palette/)
const theme = createMuiTheme({
palette: {
primary: {
// light: will be calculated from palette.primary.main,
main: '#ff4400',
// dark: will be calculated from palette.primary.main,
Run Code Online (Sandbox Code Playgroud)
我似乎找不到的是如何访问这些颜色以在我的组件中使用。在实现这样的主题之后:
const theme = createMuiTheme({
palette: {
secondary: {
main: '#287a9f'
}
}
})
Run Code Online (Sandbox Code Playgroud)
然后我将如何指定我想要一个组件使用辅助颜色的浅色变体?就像是:
<AppBar color="Primary.light" />
Run Code Online (Sandbox Code Playgroud)
我当然可以将它们手动实现为自定义颜色,但这似乎违背了自动计算的目的。
智慧大加赞赏。
我试图在 React Material-UI<Typography>元素(也在 Material-UI 中<Card>)中加粗一个词。我只是使用 html 标签,它有效:
<Typography><b>First thing:</b> {answers[2]}</Typography>
Run Code Online (Sandbox Code Playgroud)
但是当我使用它们时,它们会在加载时产生可见的文本大小调整。
我留下了嵌套<Typography>标签,这迫使我应用一堆样式以使它们正常显示:
<Typography style={{display:'inline-flex', alignItems: 'baseline'}}><Typography variant='h6' style={{marginRight:'3px'}}>Path:</Typography> {path}</Typography>
Run Code Online (Sandbox Code Playgroud)
这似乎是一个笨拙的解决方案。我错过了什么吗?像<b>标签导致加载延迟的另一个原因,或内置的 Material-UI 解决方案?
的完整代码<Card>,作为参考:
<Card className={classes.card}>
<CardActionArea>
<RenderImage imageAddress={myImage} widthAndHeight={[230, 180]} style={{marginLeft: '10%'}} />
<CardContent>
<Typography style={{display:'inline-flex', alignItems: 'baseline'}}><Typography variant='h6' style={{marginRight:'3px'}}>Path:</Typography> {path}</Typography>
<Typography><b>First thing:</b> {answers[2]}</Typography>
<Typography><b>Second thing:</b> {answers[0]}</Typography>
<Typography style={{marginBottom: 0}}><b>Third thing:</b> {answers[1]}</Typography>
</CardContent>
</CardActionArea>
</Card>
Run Code Online (Sandbox Code Playgroud) 我正在 React 中的 SPA 中工作,不使用 React Router 来创建任何路由;我不需要允许用户导航到特定页面。(想想多页调查问卷,按顺序填写。)
但是,当用户按下浏览器上的后退按钮时,我不希望他们退出整个应用程序;我希望能够在用户按下后退按钮时触发一个功能,该功能只需将页面呈现为上次选择之前的样子。(每个页面都是一个组件,它们组装在一个数组中,由currentPage状态变量(来自状态挂钩)跟踪,因此我可以简单地渲染pages[currentPage -1].
使用(如果需要)当前版本的 React Router (v5)、函数组件和 Typescript,我如何访问后退按钮事件以禁用它并用我自己的函数替换它?
(我发现的其他答案要么使用类组件、特定于旧版本 React Router 的函数,要么使用特定框架,例如 Next.js。)
任何和所有的见解都会受到赞赏。
大家好,我希望你们做得很好,对这个愚蠢的问题感到抱歉,我只是想知道 async/await 是否允许其他任务运行?
我刚刚在 MDN 上读到async wait 的缺点,其中有一部分说“它确实允许其他任务同时继续运行,但你自己的代码被阻止”。这是什么意思?是只有 async/await 才能允许其他任务运行,还是 Promise 也可以这样做?如果是这样,你们能给我举个例子吗?先感谢您 :)
reactjs ×3
material-ui ×2
asynchronous ×1
html ×1
javascript ×1
node.js ×1
promise ×1
react-router ×1
typescript ×1