Steps to import shared CSS using Styled-components

In my project using react, I've implemented styled-components for styling. One requirement is to have a shared loading background. Here is the code snippet of how I defined it:

const loadingAnimation = keyframes`
0% {
  background-position: 95% 95%;
}
50% {
  background-position: 25% 25%;
}
100% {
  background-position: 25% 25%;
}
`;

export const LoadingBackgroundStyle = css`
  background-image: linear-gradient(
    -60deg,
    ${(props) => props.theme.colors.secondary600},
    ${(props) => props.theme.colors.secondary600},
    ${(props) => props.theme.colors.secondary600},
    ${(props) => props.theme.colors.secondary700},
    ${(props) => props.theme.colors.secondary600},
    ${(props) => props.theme.colors.secondary600},
    ${(props) => props.theme.colors.secondary700}
  );
  background-size: 400% 400%;
  animation: ${loadingAnimation} 1.25s linear infinite;
`;

Then, I use it in the following way:

import styled from "styled-components";

import { LoadingBackgroundStyle } from ".../PerformerInfoCard.styled";

export const SpotifyWrapper = styled.div``;

export const SkeletonPlayer = styled.div`
  height: ${(props) => props.$height}px;
  width: 100%;
  border-radius: ${({ $borderRadius }) => $borderRadius};
  ${LoadingBackgroundStyle}
`;

`;

However, the background style doesn't show up for some reason. It does show up when I define LoadingBackgroundStyle in the same file as SkeletonPlayer. Can you help me understand what's causing this issue?

I also tried defining the CSS in the same file but that didn't work either.

Answer №1

There are three dots in the path specified for importation.

import { LoadingBackgroundStyle } from ".../PerformerInfoCard.styled";

Without knowledge of your file structure, it is likely that the correct paths should be one of the following:

import { LoadingBackgroundStyle } from "../PerformerInfoCard.styled";

or:

import { LoadingBackgroundStyle } from "./../PerformerInfoCard.styled";

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-router Link updates the URL without triggering a re-render

Currently, I am utilizing MobX in combination with React and React-router to display some orders. However, I have encountered an issue where the URL changes when using Link, but the view does not get updated accordingly. Oddly enough, a page refresh correc ...

Oops! You forgot to include the necessary getStaticPaths function for dynamic SSG pages on '/blogs/[post]'

Whenever I attempt to execute npm run build, an error occurs. The following build error occurred: Error: getStaticPaths is required for dynamic SSG pages and is missing for '/blogs/[post]'. This is the code snippet causing the issue: function ...

Synchronizing multiple file changes simultaneously in Node.js

I have a small development server set up specifically for writing missing translations into files. app.post('/locales/add/:language/:namespace', async (req, res) => { const { language, namespace } = req.params // Utilizing fs.promises l ...

Uncovering the characteristics of a GeoJSON data layer within Google Maps V3

Is there a way to access the properties of the data layer itself when loading a geoJSON file into a Google Map? I understand how to access the individual properties like posts_here, but I'm interested in obtaining the properties for the layer as a wh ...

`The challenge of a single web page not displaying correctly`

I was working on a website for a local computer building company, and I decided to make it a single-page applet. The HTML is mostly done, and I don't have much trouble with CSS. However, I encountered an issue with hiding and displaying different sect ...

Troubleshooting a JQuery AJAX Autocomplete problem involving PHP and MySQL

I am facing an issue with my autocomplete feature. It is functioning properly on one of my pages, but not on this particular page. Even though the correct number of entries is being retrieved, they all appear to be "blank" or are displayed in black text th ...

Get the application/pdf document that was just sent to you from the software backend

I am facing an issue with downloading a PDF file sent from the backend. Upon receiving a blob response, I notice that when I download and view the file, the sheets are empty, matching the expected number of sheets. Could this be a coding problem? Current ...

Efficiently bundling Angular templates using Grunt and Browserify

I am currently utilizing angular1 in conjunction with browserify and grunt to construct my application. At present, browserify only bundles the controllers and retrieves the templates using ng-include through a separate ajax call. Due to the excessive amo ...

A step-by-step guide on sending a fetch request to TinyURL

I have been attempting to send a post request using fetch to tinyURL in order to shorten a URL that is generated on my website. The following code shows how I am currently writing the script, however, it seems like it's not returning the shortened URL ...

Looking for a method to transfer response.body information from an express server (server.js) to a React client (client.js)?

I'm currently working on a project that involves setting up a REST endpoint (POST) for the backend to send response data back to my React app. The goal is to construct an HTML page and then send that HTML back to the backend team. However, the challen ...

Setting focus on the content of a Tooltip component from Material UI is possible when triggering the onKeyPress event, however, it is not possible when triggering the onClick

Utilizing the Tooltip component from MUI within my custom TooltipComponent has been an interesting experience. Much like a Dialog, users can trigger content to appear by clicking on an element (in this case, a div with the text "CLICK"). This popup content ...

Align images to the bottom of the gallery only if their heights differ

I'm currently working on an image gallery project and have encountered a problem. When all the image labels are of the same length, they align perfectly. However, if the label is longer than one line, it causes the image to move up instead of creating ...

What is the best way to activate a scrollbar exclusively for the final section in fullpage.js?

Is there a way to enable a scrollbar for the last section only in fullpage.js? This is what I attempted: $("#section3").fullpage({ scrollBar: true, fitToSection: false, }); Unfortunately, it didn't work as expected. ...

Decode a JavaScript string without the need to save it as a file

Imagine a situation where I allow a client to input a JavaScript script that needs to be sent to my server. This script is meant to export an object. Here is the frontend code snippet: <form action="/blabla.js" method="post"> ...

Encountered an issue in Typescript with error TS2554: Was expecting 0 arguments but received 1 when implementing useReducer and useContext in React

I've encountered several errors with my useReducers and useContext in my project. One specific error (TS2554) that I keep running into is related to the AuthReducer functionality. I'm facing the same issue with each Action dispatch. I've tri ...

What is the best way to delete a jQuery.bind event handler that has been created for an event

I have a div and I need to assign two scroll functions to it, but I also want to remove one of them after a certain condition is met. <div id="div1" class="mydivs"> something </div> <div id="div2">Some crap here</div> <script&g ...

Switch from using jQuery to vanilla JavaScript for handling POST requests

I am looking to eliminate the jQuery dependency and use plain JavaScript instead in the code below for a post request. <script type="text/javascript> $(function() { $.post("test_post.php", { name: "John Doe", ...

Tips for arranging a group of objects based on a nested key within each object

i have a collection of objects that I need to sort based on their id. here is the information: { 1918: { id: "1544596802835", item_id: "1918", label: "Soft Touch Salt Free Mint 500 ml (000001400045)", combo_items: false } 6325: { ...

Mastering Array Dispatch in VueJS

I've encountered an issue while trying to send an array of data to the backend. I attempted to include [] in the dispatch variables and on the backend, but it only captures the last data sent to the backend. My objective is to associate each data with ...

Unable to modify the properties of a stateless child component

I'm completely new to React and I decided to create a basic comments application. My main objective was to let users change their display pictures by clicking the 'Change Avatar' button. However, I encountered an issue where the 'Chang ...