当前位置:网站首页>Antd's tool function getprefixcls gets the public prefix
Antd's tool function getprefixcls gets the public prefix
2022-07-27 13:12:00 【I'm Feng Feng Yi】
I was there before. antd There is a practice in , Is to get the public prefix through a function .
I feel this method is very good , So I also wrote a similar tool function for extracting public prefixes
export const setCommonCls = (...wrapperPrefix: string[]) => {
return (className) =>
wrapperPrefix
.concat(className)
.reduce((prefix, curPrefix) => `${
prefix}-${
curPrefix}`);
};
The reason why I think of this is that I'm writing react Component time , The class names of general components and page components should be distinguished , Of course, if you use css module Words , This may not make much sense .
stay react In general components
If you define a general prefix, you can use
const prefix = "prefix";
const getCls = setCommonCls("comp", prefix);
console.log(getCls("demo")); // 'comp-prefix-demo'
The significance lies in the unified management when we change the prefix of class name later , Make changes
Inspiration is to see antd There is such a function in
getPrefixCls: (suffixCls?: string, customizePrefixCls?: string) => {
if (customizePrefixCls) return customizePrefixCls;
return suffixCls ? `${
getGlobalPrefixCls()}-${
suffixCls}` : getGlobalPrefixCls();
}
边栏推荐
- 2021-03-15
- JS single thread understanding notes - Original
- Open source project - taier1.2 release, new workflow, tenant binding simplification and other functions
- Dominoes staged: the beginning and end of the three arrow capital crash
- 「游戏引擎 浅入浅出」4.1 Unity Shader和OpenGL Shader
- 完美指南|如何使用 ODBC 进行无代理 Oracle 数据库监控?
- Detail the execution process of JDBC query method
- 概述静态内部类与非静态内部类
- B站713故障后的多活容灾建设|TakinTalks大咖分享
- 【表达式计算】双栈 : 表达式计算问题的通用解法
猜你喜欢

隔离级别

Open source project - taier1.2 release, new workflow, tenant binding simplification and other functions

MySQL extensions

Overview of famous inner classes and anonymous inner classes

ArrayList常用方法总结

分布式系统架构理论与组件
QT | qcheckbox of control

500强企业如何提升研发效能?来看看行业专家怎么说!

2022 global Vocational Education Industry Development Report

Set接口
随机推荐
开源项目丨Taier1.2版本发布,新增工作流、租户绑定简化等多项功能
Nodejs body parser middleware processes post form data of type multipart / form data, and req.body cannot receive data
Poj1548 robots [bipartite graph minimum path coverage]
B站713故障后的多活容灾建设|TakinTalks大咖分享
Will MySQL fail to insert data? Why?
Multi activity disaster recovery construction after 713 failure of station B | takintalks share
视频游戏沉迷行为研究综述
pg同步多张数据表至mysql 有办法简化配置吗?
隔离级别
Summary of common methods of ArrayList
Why do you need foreign keys?
592. 分数加减运算 : 表达式计算入门题
Enjoy the luxury meta universe louis:the game, and participate in the NFT series digital collection white roll activity | tutorial
Security measures for tcp/ip protocol vulnerabilities
Do you really understand CMS garbage collector?
How to get class objects
Seata's landing practice in ant International Banking
Eccv2022 | Ru & Google proposed to use clip for zero shot target detection!
初学者入门:使用WordPress搭建一个专属自己的博客
Getting started for beginners: build your own blog with WordPress