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

I'm trying to figure out how to effectively interpolate a Link component within a text that shifts its position using Next-i18next/React i18next

Currently, I am utilizing Next.js with Next-i18next for internationalization. However, I have noticed that the React/i18next setup is essentially the same. My issue arises when I need to inject a Next Link component within translated text. The challenge l ...

Struggling to populate a nested array in a dropdown using AngularJS

I am currently working on populating JSON data into a dropdown list, specifically focusing on main category, sub category and sub sub category. Successfully managed to populate the main category and sub category, but facing challenges with populating subsu ...

Array's Javascript length of 0

I have encountered some strange behavior with the following code. It's displaying an array length of 0 even though I can see a length greater than 0 when printing it right before that: var getTopSelection = function(callback) { var topSelection = ...

What is the best way to overlay text onto a background image using Material UI's Card and CardMedia components?

Using the card component, I have successfully added a background image. However, I am facing difficulty in figuring out how to overlay text on top of this image. If anyone has suggestions or alternative methods, please feel free to share! <Card> ...

The redirect function is failing to carry the "req" parameter

Express Routes Troubleshooting app.get('/auth/google/redirect', passport.authenticate('google'), (req, res) => { console.log('req.user:', req.user) //>>>>>Outputs {username: 'bob', id: '.. ...

The Asp.net MVC Navigation Bar

I'm facing an issue with the navbar in asp.net mvc Here is my code snippet <li class="nav-item nav-link" role="presentation"> <a class="nav-link" @Html.ActionLink("Customers", "Index", "Customers") /&g ...

Migrating a few PHP scripts to ColdFusion

Hey there, I'm currently in the process of converting some really basic PHP code to be compatible with a development server that only supports CF. This is completely new territory for me, so I'm looking for some guidance on how to port a few thin ...

The result of Ajax is coming back as unclear

I've encountered an issue while trying to upload an image to my server using a POST form and AJAX. Every time I submit the form, my AJAX response shows as undefined in the error box. Here is the Ajax function I am referring to: $('.register_subm ...

Retrieving JSON Data from an API with JavaScript/jQuery

Having some trouble with JSON parsing using jQuery and JavaScript. I'm trying to fetch weather information from the open weather simplest API, but for some reason it's not working. When I hardcode the JSON data into a file or my script, everythin ...

Issues with properly functioning collapse button in Bootstrap 5.1.3 Navigation Bar

When I initially click on the collapsed nav-bar button, it expands to show the nav-bar contents. However, upon clicking the button again, it fails to collapse. Below is the corresponding HTML code snippet. *<!-- CSS Stylesheet -->* <link href= ...

Only two options available: validate and hide; no additional options necessary

Having some trouble understanding the logic behind a JavaScript script that is meant to display select options based on another select option. Any tips on how to hide unused options? For example: If TV is selected, only show options for device, tsignal, b ...

Having issues with implementing the Bootstrap form-check-inline feature

I have been attempting to utilize the form-check-inline feature from Bootstrap Forms without success, as it seems to be stacking checkboxes vertically instead of inline: This is the code snippet I am working with: <h1>Create Patient</h1> < ...

Experience seamless page transitions with React Router v4's sleek animation that smoothly guides you

I implemented a fade-in fade-out transition for routed components using RR4 and ReactCSSTransitionGroup, based on the example provided in https://reacttraining.com/react-router/web/example/animated-transitions While the animations are working, I am facing ...

How to make a div stretch to full browser height using CSS and jQuery

I've been attempting to stretch a div to the browser's height using CSS in jQuery, but it doesn't seem to be working. I can successfully apply 100% width to the div, but height is proving to be a challenge. Any ideas why this might be happen ...

The dropdown menu button stubbornly remains open and refuses to close

Having an issue with a dropdown menu button where it should open when clicked on the icon and close when clicking off the icon or on the icon again, but instead, it remains open. Here is a screenshot for reference: https://i.stack.imgur.com/UX328.jpg I&a ...

What is the process of implementing FFT in node.js?

Struggling with implementing FFT in node.js is proving to be quite challenging for me at the moment. Despite experimenting with three different libraries, I find them all poorly documented, which only adds to the complexity of the task. My current setup i ...

utilizing AJAX to send a POST request and display the response in HTML using Django

I am looking to input a number into a text box and retrieve all the even numbers using ajax with Django. Here is my view: load_template @csrf_exempt def load_template(request): if request.method == 'POST': num1 = request.POST[&a ...

Unable to transfer a value from a CGI script back to an HTML form

When working with an HTML form that has a date field named cdt, I encountered the need to retain the date value when submitting data to an Oracle table through a CGI script. To achieve this, instead of using Javascript code like history.go(-1), I aimed to ...

Facing challenges in both client-side and server-side components

import axios from 'axios'; import Image from 'next/image'; export const fetchMetadata = async({params}) => { try { const result = await axios(api url); return { title: title, description: Description, } / } catch (error) { con ...

Fetch data dynamically with jQuery AJAX

I am working on a jQuery Ajax form submission to a PHP page with the goal of dynamically returning values instead of all at once. For instance, in my jQuery code: jQuery.ajax({ type: "POST", url: "$PathToActions/Accounts.php", dataType: ...