小编Ren*_*laj的帖子

JS 中的 CSS,如何让 props.className 成为优先类

我们需要那些作为 props 传递的类应该比默认类具有更高优先级的组件。

当将类作为 prop 传递时,组件优先考虑在自己的文件中创建的类。

文本.jsx

// this will be a component in another folder, it will be used in the whole app so it 
// should haveDYNAMIC styling
function Text(props) {
  const useStyles = makeStyles(theme => ({
    default: {
      fontSize: 18,
      color: "black"
    }
  }));

  const classes = useStyles();

  return (
    <div className={classNames(classes.default, props.className)}>
      {props.children}
    </div>
  );
}
Run Code Online (Sandbox Code Playgroud)

应用程序.jsx

function App() {
  const useStyles = makeStyles(theme => ({
    title: {
      fontSize: 80,
      color: "red"
    },
    notGoodPractice: {
      fontSize: …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-native material-ui react-hooks

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