Utilizing Tailwind's layer component directives on a Remix React component

I've been experimenting with creating Tailwind directives in my Remix project. However, when I define CSS classes under the components layer of tailwind.css and apply them to my React components' className(s), the styles don't seem to be taking effect.

@layer components {
    .note-view-article-container {
        @apply bg-gray-300 px-5 py-2 my-10;
    }
    .note-view-title {
        @apply border border-zinc-500 text-center text-lg
    }
}

Here is an example of a component:

export function NoteView(props: Note) {
  const { id, title } = props;
  return (
    <article className=".note-view-article-container" key={id}>
      <p className=".note-view-title">
        {title}
      </p>
      );
     }

Any suggestions on how to troubleshoot this issue? Appreciate your help!

Answer №1

Consider using

className="note-view-article-container"
rather than
className=".note-view-article-container"
. Learn how to add CSS styles in react

export function NoteView(props: Note) {
  const { id, title } = props;
  return (
    <article className="note-view-article-container">
      <p className="note-view-title">
        {title}
      </p>
    </article>
  );
}

It might be difficult to understand without viewing the complete source code of the component, but typically you do not need a key property for the <article /> element. If you intend to render NoteView within a list, ensure to assign a key property to the component:

<NoteView id={id} title={title} key={id} />

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

Error 500 on Firebase: Issue solving "firebase" in "firebase.js" not resolved

Struggling to incorporate Firebase into my latest React project, I keep encountering the dreaded "The development server returned response error code: 500." Despite creating a firebase.js file to house my Firebase configuration details, I am at a loss as ...

Updating the menu in the nextJS/ReactJS application

There's a scenario where clicking on a link named "create custom URL" changes it to "cancel" and "save". For instance: Initially, clicking on "create custom URL": https://i.stack.imgur.com/ZnBkD.png Changes to: https://i.stack.imgur.com/ubfKV.png ...

Creating a gap in an HTML document with a 'division' element and cascading style sheets

I am struggling to create a blank space between my divs. Despite trying numerous CSS properties such as margin-top, padding-top, and others from various sources online, I have not been successful. The only way I can add space is by using an excessive amou ...

The Bootstrap CDN is malfunctioning and displaying errors in the console

I attempted to incorporate Bootstrap 4.5 using the CDN provided on their main website. However, after adding all the code lines to my project, I encountered numerous issues with my custom CSS and the Bootstrap carousel failing to function. Upon inspecting, ...

Embarking on the journey of nesting components within styled-components

Check out these custom components I created: <UserImg imgUrl={userPhoto}> <DropDown> <div onClick={handleAuth}>Sign Out</div> </DropDown> </UserImg> const DropDown = styled.div` letter-spacing: 0.2em; positi ...

IE and Chrome are experiencing issues where the radio buttons are disappearing

Here is the style sheet code: select,input ,td a {border:1px solid green; width:25%;height:25px;font-size:20px;margin- left:.1em;} input.myradio {border:none;width:0%;height:0%;font-size:0%;} And here is the corresponding HTML code: <td><inpu ...

How to target the following sibling element (not a child) with CSS

I am working with the following HTML structure: <div class="col-sm-12"> <input id="my_id"> <div class="col-sm-1 col-3-box" style="position:absolute; margin-left:340px;"> </div> </div> How can I target and change ...

Learn how to use Bootstrap to style your buttons with centered alignment and add a margin in between each one

Looking to center four buttons with equal spacing between them? Here's what you can do: |--button--button--button--button--| Struggling with manual margin adjustment causing buttons to overlap? Check out this code snippet: <div id=""> ...

In the context of ReactJS, how should the src property be formatted within an img tag to reference a mapped json file correctly?

Currently, I am trying to incorporate images from a local JSON file into my component. These images need to correspond with the data obtained from an API call. The contents of my JSON file are as follows: [ { "id": 1, "dwarf" ...

Steps to eliminate the gap between the link element and toggler in Bootstrap 4

Incorporating the code below will create a navigation bar with a cart icon in Bootstrap 4, indicated by the images. The expanded view showcases the cart next to the search section on the right. When viewed on smaller devices in collapsed mode, it should al ...

Exploring the depths of routing with React Router DOM Version 6

Hello everyone, I trust you are all doing well. Recently, I completed a project using React and created a demo here. The issue I'm facing is related to routing. My intention is to display the child route under its parent but unfortunately, I haven&apo ...

Tips for storing information in MongoDb alongside an image

I am trying to store details in MongoDB and upload images to an "images" folder using Multer, but I am facing issues with retrieving the data on the server-side. const onSubmit = async (object) => { const fd = new FormData() fd.append(&a ...

Updating parent data when new data is added in child component in React

I'm just starting to learn React and I've been reading a lot about updating children components when the parent component is updated, but I haven't come across much information about the opposite scenario. Currently, I have a parent compone ...

Unable to create a Next 13 application using react-quill

My NextJS app includes the react-quill library for rich text editing. Previously, I had no issues with importing the library dynamically to avoid server-side rendering problems. However, after upgrading to Next 13, I encountered a problem. During the bui ...

Tips for styling expandIcon in MUI Accordion while the Accordion is in its expanded state

Seeking help in removing the padding-top from the ExpandIcon within the Accordion component when it is expanded. I'm currently exploring the documentation provided by MUI on how to target specific styles and states, but finding it challenging to compr ...

How to enhance a class in JavaScript by adding a dynamic property

Within my code, I've defined a class which looks like this: class classA { id: number; name: string; constructor(data){ this.id = data?.id || 0; this.name = data?.name || ''; } } What I aim to do now is add ...

Display elements exclusively when the class XY is in an active state using JavaScript

Hello everyone, I'm new to this platform and excited to share my first post. Currently, I find myself facing a major challenge as I navigate through a bootcamp program. I have been working on a website with different sections that require specific fu ...

Ways to distinguish between bot ID and user ID in a React web chat interface without any additional design elements

I am trying to personalize my Bot using the Plain web chat UI created by Microsoft Bot. If you want to see a sample of it, you can check out this Sample Link I am fairly new to React and Web Chat. I have a question regarding how to distinguish between co ...

To optimize your bundling process, include the leaflet.css file from the node_modules/leaflet directory using webpack

Currently, I am working on developing a map application using webpack and leaflet. While I can successfully require leaflet.js from my map.js file, I encounter an error when trying to call leaflet.css. The configuration in my webpack.config.js is as follo ...

Guide on integrating HTML from a response into the render function in React JS

I've been doing some research but I'm struggling to find a good solution for this issue. I have a response that looks like this: "name": "another test", "description": "para hacer el aseo", &quo ...