SCSS in React Native? Here’s How!

React Native provides great styling capabilities, but working with plain stylesheets can sometimes feel limiting. brings more flexibility and organization to your styles, making development smoother.

In this guide, we’ll walk you through setting up SCSS in React Native and making the most of its features. Let’s get started!

React Native provides great styling capabilities, but working with plain stylesheets can sometimes feel limiting. If you’ve ever found yourself repeating styles across multiple components or struggling to maintain consistency, Syntactically Awesome Style Sheets (SCSS) can be a game-changer. SCSS brings more flexibility and organization to your styles, making development smoother.

In this guide, we’ll walk you through setting up SCSS in React Native and making the most of its features. Let’s get started!

Create a React Native Project

React Native comes with Metro, the dedicated bundler that takes your React Native code and assets, packages them together, and prepares them to be run on a mobile device. Before setting up SCSS, you need to create a new React Native project. Use these steps to get started:

  1. Run the command npx @react-native-community/cli@latest init AwesomeProject
  2. Run the command npm run android

SCSS Setup

1. Install the required dependencies by running the following command:

npm install babel-plugin-react-native-classname-to-style babel-plugin-react-native-platform-specific-extensions react-native-sass-transformer sass --save-dev

2. Update the babel.config.js file to include the necessary plugins:

module.exports = {
  presets: ['module:@react-native/babel-preset'],
  plugins: [
    'react-native-classname-to-style',
    [
      'react-native-platform-specific-extensions',
      {
        'extensions': ['scss', 'sass'],
      },
    ],
  ],
};

3. Update the metro.config.js file to ensure Metro can process SCSS files:

const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');

/**
 * Metro configuration
 * https://reactnative.dev/docs/metro
 *
 * @type {import('@react-native/metro-config').MetroConfig}
 */

module.exports = (async () => {
    const defaultConfig = getDefaultConfig(__dirname);

    const customConfig = {
      transformer: {
        babelTransformerPath: require.resolve('react-native-sass-transformer'),
      },
      resolver: {
        sourceExts: [...defaultConfig.resolver.sourceExts, 'scss', 'sass'],
      },
    };

    return mergeConfig(defaultConfig, customConfig);
})();

4. Create a styles.scss file as define your desired files:

.container {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f5fcff;
}
  
.blue {
  color: blue;
  font-size: 30px;
  font-weight: bold;
}

.image {
  margin-top: 20px;
  width: 200px;
  height: 200px;
}

5. Apply the styles in the App.tsx file:

import styles from './styles.scss';

const BlueText = () => {
  return <Text style={styles.blue}>Trailhead Technology</Text>;
};

function App(): React.JSX.Element {
  const isDarkMode = useColorScheme() === 'dark';

  const backgroundStyle = {
    backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
  };

  return (
    <SafeAreaView style={backgroundStyle}>
      <StatusBar
        barStyle={isDarkMode ? 'light-content' : 'dark-content'}
        backgroundColor={backgroundStyle.backgroundColor}
      />
      <ScrollView
        contentInsetAdjustmentBehavior="automatic"
        style={backgroundStyle}>
        <Header />
        <View style={styles.container}>
          <Image
            source={require('./assets/trailhead.jpg')}
            style={styles.image}
          />
          <BlueText />
        </View>
      </ScrollView>
    </SafeAreaView>
  );
}

Some Tips

You may get an error while importing the style like “Cannot find module ‘./styles.scss’ of its corresponding type declarations.”:

If you do, this means you must add a file called loaders.d.ts on the root folder of your code:

Put the following content in the loaders.d.ts file you just created:

declare module '*.css';
declare module '*.scss';
declare module '*.jpeg';
declare module '*.jpg';
declare module '*.gif';
declare module '*.png';
declare module '*.svg';
declare module '*.json';

These module declarations in TypeScript tell the compiler to treat files with these extensions as importable modules, even if they don’t have explicit type definitions. This is particularly useful when working with assets like images, styles, or JSON files in a TypeScript-based React Native project.

Result

Below is a screenshot of a sample application I built showing how you can add custom SCSS styles and content in a React Native app.

Conclusion

Using SCSS in React Native enhances styling by introducing powerful features like variables, nesting, and mixins, leading to more structured and maintainable styles. While React Native doesn’t natively support SCSS, tools like react-native-sass-transformer enable its use, making it easier to manage styles in large React Native projects.

Further Reading

Picture of Junior Saravia

Junior Saravia

Junior Saravia earned his B.S. in Systems Engineering from the National University of Engineering in Lima, Peru. He has 5 years of experience in cross-platform Mobile Development using Xamarin and now .NET MAUI. He has been focused on keeping up-to-date with new technology trends such as IoT, microcontrollers, and various coding best practices. His strong collaboration and adaptability to face up to challenging projects have proven his ability to offer valuable solutions to clients through complex technologies. Beyond the realm of technology, Junior enjoys practicing soccer, swimming, and the freedom of biking outdoors.

Free Consultation

Sign up for a FREE consultation with one of Trailhead's experts.

"*" indicates required fields

This field is for validation purposes and should be left unchanged.

Related Blog Posts

We hope you’ve found this to be helpful and are walking away with some new, useful insights. If you want to learn more, here are a couple of related articles that others also usually find to be interesting:

Our Gear Is Packed and We're Excited to Explore With You

Ready to come with us? 

Together, we can map your company’s software journey and start down the right trails. If you’re set to take the first step, simply fill out our contact form. We’ll be in touch quickly – and you’ll have a partner who is ready to help your company take the next step on its software journey. 

We can’t wait to hear from you! 

Main Contact

This field is for validation purposes and should be left unchanged.

Together, we can map your company’s tech journey and start down the trails. If you’re set to take the first step, simply fill out the form below. We’ll be in touch – and you’ll have a partner who cares about you and your company. 

We can’t wait to hear from you! 

Montage Portal

Montage Furniture Services provides furniture protection plans and claims processing services to a wide selection of furniture retailers and consumers.

Project Background

Montage was looking to build a new web portal for both Retailers and Consumers, which would integrate with Dynamics CRM and other legacy systems. The portal needed to be multi tenant and support branding and configuration for different Retailers. Trailhead architected the new Montage Platform, including the Portal and all of it’s back end integrations, did the UI/UX and then delivered the new system, along with enhancements to DevOps and processes.

Logistics

We’ve logged countless miles exploring the tech world. In doing so, we gained the experience that enables us to deliver your unique software and systems architecture needs. Our team of seasoned tech vets can provide you with:

Custom App and Software Development

We collaborate with you throughout the entire process because your customized tech should fit your needs, not just those of other clients.

Cloud and Mobile Applications

The modern world demands versatile technology, and this is exactly what your mobile and cloud-based apps will give you.

User Experience and Interface (UX/UI) Design

We want your end users to have optimal experiences with tech that is highly intuitive and responsive.

DevOps

This combination of Agile software development and IT operations provides you with high-quality software at reduced cost, time, and risk.

Trailhead stepped into a challenging project – building our new web architecture and redeveloping our portals at the same time the business was migrating from a legacy system to our new CRM solution. They were able to not only significantly improve our web development architecture but our development and deployment processes as well as the functionality and performance of our portals. The feedback from customers has been overwhelmingly positive. Trailhead has proven themselves to be a valuable partner.

– BOB DOERKSEN, Vice President of Technology Services
at Montage Furniture Services

Technologies Used

When you hit the trails, it is essential to bring appropriate gear. The same holds true for your digital technology needs. That’s why Trailhead builds custom solutions on trusted platforms like .NET, Angular, React, and Xamarin.

Expertise

We partner with businesses who need intuitive custom software, responsive mobile applications, and advanced cloud technologies. And our extensive experience in the tech field allows us to help you map out the right path for all your digital technology needs.

  • Project Management
  • Architecture
  • Web App Development
  • Cloud Development
  • DevOps
  • Process Improvements
  • Legacy System Integration
  • UI Design
  • Manual QA
  • Back end/API/Database development

We partner with businesses who need intuitive custom software, responsive mobile applications, and advanced cloud technologies. And our extensive experience in the tech field allows us to help you map out the right path for all your digital technology needs.

Our Gear Is Packed and We're Excited to Explore with You

Ready to come with us? 

Together, we can map your company’s tech journey and start down the trails. If you’re set to take the first step, simply fill out the contact form. We’ll be in touch – and you’ll have a partner who cares about you and your company. 

We can’t wait to hear from you! 

Thank you for reaching out.

You’ll be getting an email from our team shortly. If you need immediate assistance, please call (616) 371-1037.