Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
react-css-modules no funciona correctamente

Quiero usar react-css-modules, pero cuando uso className styles.myBtn en el código, obtengo esta clase N6OJGonmM2EqyZqImevh en el navegador en lugar de myBtn_ .

paquete.json

 { "name": "curairs", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "build": "webpack", "start": "webpack-dev-server --open" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "@babel/core": "^7.15.8", "@babel/polyfill": "^7.12.1", "@babel/preset-env": "^7.15.8", "@babel/preset-react": "^7.14.5", "babel-loader": "^8.2.2", "clean-webpack-plugin": "^4.0.0", "css-loader": "^6.4.0", "file-loader": "^6.2.0", "html-webpack-plugin": "^5.4.0", "less-loader": "^10.2.0", "mini-css-extract-plugin": "^2.4.2", "react": "^17.0.2", "react-css-modules": "^4.7.11", // !!! "react-dom": "^17.0.2", "react-redux": "^7.2.5", "redux": "^4.1.1", "redux-thunk": "^2.3.0", "style-loader": "^3.3.0", "webpack": "^5.58.2", "webpack-cli": "^4.9.1", "webpack-dev-server": "^4.3.1" } }

codigo css

 .myBtn{ color: blue; }

Componente.jsx

 import React from "react"; import styles from "./myBtn.module.css"; const Component=()=>{ return( <div> <button className={styles.myBtn}>1234</button> </div> ) } export default Component;

¿Cómo obtener la clase de tipo Component_myBtn_XxXx ?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Si el nombre de archivo de su componente es Component y su código es así:

 const Component=()=>{ return( ... ) }

Suponga que tiene un archivo css junto al Component cuyo contenido es:

 .myBtn{ color: blue; }

Entonces, el archivo css debe llamarse: Component.module.css . Finalmente, puedes usarlo así:

 import React from "react"; import styles from "./Component.module.css"; const Component=()=>{ return( <div> <button className={styles.myBtn}>1234</button> </div> ) } export default Component;

Editar sharp-chebyshev-hur4b

about 4 years ago · Juan Pablo Isaza Report

0

Tuve que agregar esto en webpack.cofig

 { test: /\.css$/, use: [ MiniCssExtractPlugin.loader, { loader: "css-loader", options: { importLoaders: 1, modules:{ localIdentName: '[name]__[local]___[hash:base64:5]' }, }, }, ], include: /\.module\.css$/, }, { test: /\.css$/, use: [MiniCssExtractPlugin.loader,"css-loader"], exclude: /\.module\.css$/, },
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!