当前位置:网站首页>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();
}
边栏推荐
- About typora's inability to log in after March 9, 2022 -- resolved
- Baoli food listed on Shanghai Stock Exchange: annual revenue of 1.578 billion, market value of 5.8 billion
- Minimally invasive brain science broke the listing: the company's market value is HK $14.3 billion, and minimally invasive medical is the major shareholder
- CVPR22 | 关系意识的图神经架构搜索
- POJ2594 Treasure Exploration【二分图最小路径覆盖】【Floyd】
- POJ1548 Robots【二分图最小路径覆盖】
- 概述静态内部类与非静态内部类
- Poj1548 robots [bipartite graph minimum path coverage]
- 如何获取Class类对象
- CEPH distributed storage performance tuning (6)
猜你喜欢

multi-table query

CEPH distributed storage performance tuning (6)

Dominoes staged: the beginning and end of the three arrow capital crash

How can the top 500 enterprises improve their R & D efficiency? Let's see what industry experts say!

BSP视频教程第21期:轻松一键实现串口DMA不定长收发,支持裸机和RTOS,含MDK和IAR两种玩法,比STM32CubeMX还方便(2022-07-24)

"Game engine light in light out" 4.1 unity shader and OpenGL shader

Mixin\ plug in \scoped style

4. Analysis of the execution process of make modules for general purposes

开源项目丨Taier1.2版本发布,新增工作流、租户绑定简化等多项功能

Error: the source of the existing CacheManager is: urlconfigurationsource
随机推荐
分布式系统架构理论与组件
PG synchronizes multiple data tables to MySQL. Is there a way to simplify the configuration?
BSP video tutorial issue 21: easy one key implementation of serial port DMA variable length transceiver, support bare metal and RTOS, including MDK and IAR, which is more convenient than stm32cubemx (
GAN:生成对抗网络 Generative Adversarial Networks
Lambda expression
Use redis' sorted set to make weekly hot reviews
592. 分数加减运算 : 表达式计算入门题
heap
Poj1273 drainage ditches [maximum flow] [SAP]
Set interface
[nuxt 3] (XII) project directory structure 2
II. Analysis of the execution process of make menuconfig
详述jdbc查询方法执行过程
详述HashSet的add方法
4. Analysis of the execution process of make modules for general purposes
POJ1273 Drainage Ditches【最大流】【SAP】
概述静态内部类与非静态内部类
Soft core microprocessor
Security measures for tcp/ip protocol vulnerabilities
SQL statement problem, calculate the data with a difference of less than 10 minutes to be displayed as the same batch of data