【发布时间】:2021-10-19 16:22:00
【问题描述】:
我有一个基于mui-org/material-ui 的组件库dot-components。我有另一个应用程序正在使用我的 dot-components 组件库,最近我注意到我的单元测试中出现了控制台警告。
控制台警告
console.warn
Material-UI: The `css` function is deprecated. Use the `styleFunctionSx` instead.
at css (../../node_modules/@material-ui/system/styleFunctionSx.js:75:13)
at Object.<anonymous> (../../node_modules/@material-ui/core/Box/Box.js:14:37)
at Object.<anonymous> (../../node_modules/@material-ui/core/Box/index.js:21:36)
有问题的控制台警告与mui-org/material-ui PR #23454 有关,但是我已经检查了我的应用程序以及dot-components 并确认我们根本没有使用Box。我查看了所有堆栈溢出并在网上搜索了所有可能的地方。我什至尝试在mui-org/material-ui #27799 中询问它,但他们更关心的是解决问题而不是实际帮助。
我在这里没有选择,我唯一能想到的是 MUI 正在抛出警告,因为它在我的样式组件中看到了 css 的使用
样式化组件示例
import styled, { css } from 'styled-components';
export const StyledProductInstancesList = styled.div``;
export const StyledCard = styled(DotCard)`
${({ theme }) => css`
margin-bottom: ${theme.spacing(1)}px;
`}
`;
我将sandbox 与我所看到的问题的一个非常清晰的最小示例放在一起。
正在导入的包
@material-ui/core: 4.11.4
@material-ui/styles: 4.11.4
@material-ui/system: 4.12.1
@material-ui/types: 5.1.0
@material-ui/utils: 4.11.2
@types/react: 16.9.56 => 16.9.56
react: 17.0.1 => 17.0.1
react-dom: 17.0.1 => 17.0.1
styled-components: 5.2.1 => 5.2.1
typescript: ~4.0.3 => 4.0.7
【问题讨论】:
-
请显示在
dot-components中使用的所有@material-ui包版本。由于无法看到使用的dot-components代码和包,因此很难猜测警告的原因。 -
我认为可能的原因是您的
@material-ui/core版本比您的@material-ui/system版本旧。 -
就声称您没有使用
Box而言,我怀疑您正在执行诸如import {Button} from "@material-ui/core"之类的导入而不是import Button from "@material-ui/core/Button",因此在@material-ui/core中执行index.js导入所有组件,包括Box。 -
@RyanCogswell 我已经根据您的要求更新了我的问题。另外你是对的,我们正在做命名导入,但如果我们具体说明我们的导入,例如
import {Button} from "@material-ui/core",那将如何导入我们没有明确导入的组件?
标签: reactjs material-ui styled-components