Using external components, such as antd, with Style JSX in a NextJS project is not functional

I am exploring the use of Style JSX within a Next JS application to customize AntD components, with a focus on customizing the appearance of the sidebar (specifically using Style JSX to modify AntD's Sider component). Below is a snippet of the code I am working with:

   <>
        <Sider collapsible collapsed={collapsed}
        onCollapse={onCollapse} id='left-sidebar'
        >
            <div id='components-layout-demo-side'/>
            <Menu theme="light" defaultSelectedKeys={['1']} mode="inline">
                <Menu.Item key="1" icon={<PieChartOutlined />} >Option 1</Menu.Item>
                    
                <Menu.Item key="2" icon={<DesktopOutlined />} >Option 2</Menu.Item>
                        
            </Menu>
            // style jsx here
        </Sider>
        // or style jsx here
   </>

One customization I envision is changing the background color to something different. My attempts so far include:

  1. Trying to target the element by its id like this:
    <style jsx>{`
        #left-sidebar { background-color: #fff }
    `}</style>
  1. Another attempt involved referencing the resulting HTML element, specifically an aside tag (including the corresponding classname ant-layout-sider).

  2. I also experimented with using css.resolve as per the Next JS documentation for external components, but without success.

Unfortunately, none of these methods seem to apply the styles in the browser when inspected closely. While other approaches like global CSS files and CSS-modules work, the usage of style jsx in this scenario seems problematic despite following the guidelines provided by NextJs.

My assumption is that the framework may be stripping away the CSS styles before rendering the elements. So, my question remains - is it simply not feasible to achieve this, or is there a crucial step that I am overlooking? The example above is borrowed from Antd Layouts Sider.

Answer №1

It appears you may have overlooked a small mistake in the code snippet you provided:

<style jsx>
        #left-sidebar { background-color: #fff }
</style>

You forgot to include {` `}

<style jsx>{`
        #left-sidebar { background-color: #fff }
`}</style>

Check out the Next.js documentation for more information.

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

Looking to create circular text using HTML, CSS, or JavaScript?

https://i.sstatic.net/pnu0R.png Is there a way to generate curved text in HTML5, CSS3, or JavaScript similar to the image linked above? I've experimented with transform: rotate(45deg); but that just rotates the text without curving it. Additionally, ...

Developing a dynamic row that automatically scrolls horizontally

What is the best method for creating a div box containing content that automatically slides to the next one, as shown by the arrows in the picture? I know I may need jquery for this, but I'm curious if there's an alternative approach. oi62.tinyp ...

Leverage the power of openCv.js within your next.js projects

I am attempting to incorporate openCv.js into my next.js application a. I started the project with: npx create-next-app b. Next, I installed: $ yarn add @techstark/opencv-js c. Imported OpenCV with: import cv from "@techstark/opencv-js" d. Ho ...

What are the steps to resolve the error 'content-type missing boundary' and encountering the issue with getBoundary not being recognized as a function?

fetchCarouselData: async (params) => { let bodyFormData = new FormData(); for (let prop in params) { bodyFormData.append(prop, params[prop]); } return axios({ method: "post", url: `${baseURL}/fetchCarouselData`, data: b ...

When the virtual keyboard is opened on the Nexus Player using an Android Cordova app, the first character is automatically typed

While my question may be specific to a particular device, I am seeking insights on how to prevent a common issue from occurring in general. My ReactJS app has a build for Android using Cordova, with one of the supported devices being the Nexus Player. The ...

Looking to implement a CSS banner image for seamless customization across multiple pages

Is it possible to change the banner image easily in the CSS without having to update every HTML page? I don't want the image source to be directly on the HTML pages. How can this be achieved? Additionally, there are already two references in the CSS: ...

space required on the upper side of the cell

I have formatted a text (including title and paragraph) in a cell using CSS styles to achieve the desired appearance. The only thing left is to create some space between the top of the Title and the content below it. I attempted to use the margin parameter ...

Is it possible for a CSS Transition/Transform to ease out smoothly yet not ease in at all?

It appears that the transition is smoother when I stop hovering over the button, compared to when I actually hover. Why might this be? .button_1 { border-width: 0.8px; border-color: Lightgray; background-color: hsla(209, 72%, 59%, 0.85); ...

The "exports" section does not define the subpath '.providers/...' specified in the Next-auth package

Encountered a problem while using Next-auth Server Issue Error: Subpath './providers/google' is not defined in exports in C:\Users...\node_modules\next-auth\package.json Can anyone offer assistance? ...

React application not displaying element properly?

I am facing an issue with my react modal that displays a sign-in and sign-up form. The problem arises when I try to access the button on the form using its id, which is modal-sign-in-submit-button. document.getElementById('modal-sign-in-submit-button ...

The React Bootstrap Table features a button in every row that triggers a modal. However, clicking on a specific button causes the modal to render multiple times

I have a React Bootstrap Table, with 20 records displayed on each page. Each row contains a button added through the following code: function attachFormatter(cell, row){ return ( <AttachmentManager /> ); } <TableHeaderColumn k ...

Positioning divs next to each other in CSS and setting the width of the second

I am attempting to position two divs next to each other. The initial one is 200x200 pixels and the second one should be positioned 10 pixels to the right of the first one. The second div has a height of 200 pixels, and its width needs to extend all the way ...

How can you prevent an element from overflowing when employing window.pageYOffset and using a switch case to alter the background color at specified pixel thresholds?

I want the <body> element's background-color to change every 500px as I scroll down. I've scoured the web for answers, but still can't figure out what's going wrong. Please review the code. However, Firefox Browser indicates that ...

Steps to resolve the findDOMNode error in MaterialUI tooltip

After researching various solutions on StackOverflow to eliminate the findDOMNode warning, as well as checking out https://material-ui.com/components/tooltips and https://material-ui.com/guides/composition/#wrapping-components, I still haven't been ab ...

The Material UI read-only rating component fails to update even after the data has been successfully loaded

I have a rating component in my child component, and I am passing data from the parent component through props. However, there seems to be an issue with the MUI rating value not updating when the data is ready for viewing. https://i.sstatic.net/bqSfh.jpg ...

Trouble accessing setState within an axios call in ReactJs

I've encountered an issue while attempting to set the state of the variable isCorrectAnswer within an axios call. The error message Cannot read properties of undefined (reading 'setState') is showing up in the console log. What mistake am I ...

Achieve full height for the span tag within a div using CSS styling

I am facing a particular scenario: In a bootstrap row with 2 columns: - the first column contains a table with a button to add new rows - the second column has a label and a span (although it doesn't have to be a span) Both columns have equal hei ...

Adjust the width of an item on CSS Grid upon hovering

I recently created a basic CSS grid layout with the following structure... .container { display:grid; grid-template-columns:1fr 1fr 1fr 1fr; } .col1 { padding:20px; background:red; color:white; text-align:center; } .col2 { padding:20px; ...

Guide on how to conditionally render Container Classes

Initially, the designer provided me with this: Essentially, a category is passed from the previous screen. Through some UI interactions, I have to render this screen repeatedly. The flow goes like this: you choose a category, if it has subCategories, allo ...

Utilize React hooks to initialize a third-party library

I am looking to set up a Swiper instance in React using hooks. I want the Swiper instance to be initialized when a specific component is mounted, and then updated or destroyed based on the viewport width during resize. To achieve this, I am utilizing the ...