score:1

1. config sass modules

if you created your project with create-react-app, only thing you need to do is adding module prefix to your filename.

rename button.scss to button.module.scss

but if not, you should set modules option to true inside your sass-loader.

// webpack.config.js

 module: {
    rules: [
      {
        test: /\.(sass|scss)$/,
        use: [
          {
            loader: 'sass-loader',
            options: {
              modules: true
            },
          },
        ],
      },
    ],
  },

2.change your jsx to following

import buttonstyles from 'button.module.scss'


<button classname={buttonstyles.button__primary}>submit</button>

Related Query

More Query from same tag