Guide to effectively implement @apply in a React component leveraging css modules

Within the global stylesheet, I have defined the following:

:root {
    --font: {
        font-family: "Source Sans Pro", sans-serif;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

Then in the style.css file of a react component, I include the following:

.rightnav {
    @apply --font;
    float: right;
    color: white;
}

When using this component in my code, I encounter an error stating: No custom properties set declared for font.

Answer №1

It is important to include the global stylesheet in the local one when using postcss-apply. This is because postcss-apply does not have visibility of the global file during parsing of the local file. To address this issue, it is recommended to create a partial file that contains only custom properties and custom property sets declarations.

If you encounter this situation, consider utilizing postcss-import

@import 'path/to/variables.css';

.rightnav {
  @apply --font;
  float: right;
  color: white;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The React Native Device Info causes the android app to crash

After successfully using the react-native-device-info library in my react-native app for a year, I encountered a sudden crash on Android due to this library in the past two weeks. The error message I'm receiving is: https://i.sstatic.net/T83ba.jpg ...

Tips for adjusting the workarea height to maximize screen space in Svg-edit

Is it possible to dynamically adjust the workarea height of svg-edit to fit the screen height? Currently, you can change the workarea size in the config.js file (for example 640x480, 800x600). But how can I resize the workarea to fit the screen dynamically ...

Arrange the child elements using flexbox styling

Greetings. I am facing some challenges in positioning child elements within a flexbox container with the flex-direction:column property. Can anyone advise on how to place the sign up element next to the sign in element? https://i.sstatic.net/p3DaO.png ht ...

What elements are needed to design a high-level webpage layout such as this?

I have a current React Web application that utilizes a CSS Grid for website layout, structured as follows: ................... HEADER ...................... NAV MENU | MAIN AREA | RIGHT SIDEBAR .................. FOOTER ...................... ...

"Modifying the form-control-lg class in Bootstrap and AngularJS affects input size exclusively, leaving the label unaffected

Currently, I am focusing on enhancing an AngularJS custom text input component: <div class="form-group has-feedback" ng-class="[$ctrl.sizeClass, {'has-error': $ctrl.isNotValid(), 'has-success': $ctrl.isValid()}]" > ...

Implementing multiple condition-based filtering in React Native for arrays

I am looking to apply multiple filters to an array based on certain conditions defined by toggling switches. The issue arises when toggling two or more switches simultaneously, resulting in an empty array. My goal is to retrieve an array containing the tru ...

Why is React's nested routing failing to render properly?

click here for image portrayal I am currently attempting to integrate react router, specifically a nested router. However, when I click the links on the contact page, no results are being displayed. Any assistance would be greatly appreciated. For more in ...

What could be causing the abundance of API calls from Yandex Metrica?

In my Nextjs SPA, there is an iframe widget that is rendered using React. Inside this widget's index.html file, I have inserted the Yandex Metrica script and set up a goal tag to track user clicks on the registration button. The goal tracking is wor ...

What causes TypeScript to malfunction when using spread in components?

What is the reason for typescript breaking when props are sent to a component using a spread statement? Here's an example code snippet: type SomeComponentProps = Readonly<{ someTitle: string }> const SomeComponent = ({ someTitle }: SomeCompo ...

Combining CSS styles

Currently, I am in the process of integrating RTL support into a vast framework. To achieve this, I have replaced all directional rules with mixins like: a { @include padding(0, 1px, 0, 0); @include margin(0, 1px, 0, 0); } This implementation ensures ...

Div overlaps div on certain screen dimensions

When the screen size falls within a specific range, typically in the low 1000s, there is an issue where my content div overlaps completely with the navigation div. It appears as if both divs are positioned at the top of the page. Below is the HTML code sn ...

Can the dimensions of an element be determined before adding it to the DOM using HTML, CSS, and JS?

My current task involves dynamically creating HTML elements using JavaScript. Here is an example: var newElement = document.createElement("div"); newElement.innerHTML = _data[i].content; newElement.className = "custom"; When the ...

React JS issue with SVG linearGradient not displaying accurate values

Within my component, I am working with SVG paths and a linearGradient value passed down from the parent component through static data. The properties 'startColor' and 'stopColor' are used to define the gradient colors for each element. ...

Creating a Reactjs application for an image slider that utilizes two child components

Currently, I am facing an issue with the display of selected images in my two child components that are being called from App.js. The problem lies in setting the currentIndex value properly within the child components. My main requirement is to have the im ...

Adjusting background image positioning for different screen sizes

Can anyone help me figure out how to adjust my CSS so that when my device screen is small, a specific section of the background image is displayed instead of just the center? Here is how my background image is currently set: background-image: url(*.jpg); ...

The videoplayer is unable to playback any previously saved video blobs

Currently, I am working on developing a small video recorder app for my friend's master thesis. The main purpose of this app is to allow participants to record themselves using the webcam, as well as to explore the functionalities of a specific API th ...

Adding a three.js object on top of a Mapbox map is a great way to enhance

Currently, my setup includes react, react-map-gl, and three.js. I'm exploring the option to render a .obj file on top of the react-map-gl. If I comment out the deck.gl code/react-map-gl code, I can successfully display my .obj file on the screen usin ...

Checking the validity of email domains in real-time using Javascript

Is there a way to dynamically validate domains using JavaScript? I have a specific requirement which involves validating domains that are dynamically generated from user input. The goal is to match the domain with the company name selected and determine i ...

The key used with react-native-router-flux Actions is invalid and causes an error when invoked

The previous code was functioning properly on RN 0.57.4, but in order to publish the app on the play store, I had to upgrade it to version 0.61.4. Below is the main router being used: <Router sceneStyle={styles.allSceneStyle} navigationBarStyle={styles ...

Using either prop type for a React component in Typescript

Looking to build a Table component that can either render data from a prop or accept custom rendering via children. In order to achieve this, I need a type that can handle both scenarios with either data or children. I've come across some solutions a ...