Issue with styled-components not being exported

Issue: ./src/card.js There was an import error: 'Bottom' is not exported from './styles/cards.style'.

card.js

import React from 'react'

import {
  Bottom,
  Color,
  Text,
  Image
} from "./styles/cards.style";

function Card(props) {
  return (
    <div>
      <Bottom>
        <Color />
        <Text>{props.text}</Text>
        <Text>{props.text}</Text>
      </Bottom>
      <Image
        alt=""
        src={props.image}
      />
    </div>
  );
}

export default Card;

cards.style

import styled from "styled-components";

export default {
  colors: {
    black: "rgba(0,0,0,1)",
    brandPrimary: "rgba(238,120,36,1)",
    brandPrimaryLight: "rgba(255,184,8,1)",
    brandTertiary: "rgba(0,65,125,1)",
    darkSlateGray: "rgba(51,51,51,1)",
    white: "rgba(255,255,255,1)"
  },
  fonts: {
    uiMainContent: {
      family: "Poppins",
      size: "15px",
      weight: "300",
      lineHeight: "21px"
    },
    uiSubContent: {
      family: "Poppins",
      size: "13px",
      weight: "300",
      lineHeight: "20px"
    }
  }
};

export const Bottom = styled.div`
  width: 100%;
  height: calc(100% - 20px);
  background-color: ${props => props.theme.colors.white};
  border-radius: 4px;
  padding: 0 0 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  position: relative;
`;
export const Color = styled.div`
  height: 120px;
  background-color: ${props =>
    props.theme.colors.brandPrimary};
  margin-bottom: 16px;
  border-radius: 4px 4px 0px 0px;
  align-self: stretch;
`;
export const Text = styled.p`
  color: ${props => props.theme.colors.black};
  margin-left: 16px;
  letter-spacing: 0.1px;
  font-family: ${props =>
    props.theme.fonts.uiSubContent.family};
  font-size: ${props =>
    props.theme.fonts.uiSubContent.size};
  font-weight: ${props =>
    props.theme.fonts.uiSubContent.weight};
  line-height: ${props =>
    props.theme.fonts.uiSubContent.lineHeight};
  &:not(:last-of-type) {
    margin-bottom: 4px;
  }
`;
export const Image = styled.img`
  width: 150px;
  height: 92px;
  position: absolute;
  left: 29px;
  top: 14px;
`;

In the process of creating cards in reactjs. Normally use scss but need to utilize props later for dynamic component creation. Unsure why it's giving an error as I did export Button. Any insights on what might be causing this issue would be greatly appreciated.

Answer №1

If you want to export multiple things from the same file, avoid using export default as the first thing in your code. Instead, export each const/function individually for better organization.

For ReactJS/NextJS projects, consider creating a global theme in a separate file like global.js. This allows you to define styles such as color variables and apply them consistently throughout your application.

// global.js
const GlobalStyle = createGlobalStyle`
  * {
    box-sizing: border-box;
  }

  :root {
    --black: rgba(0,0,0,1);
    --brandPrimary: rgba(238,120,36,1);
    ...
}

Check out this resource here for more insights on styled components and global styles.

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

Calendar Complete If a month has no scheduled events, the calendar will seamlessly move on to the next month

Is it possible to set up full calendar so that it automatically advances to the next month if there are no events scheduled? For example, if there are no events in June or all events have already taken place, can the calendar automatically move on to July ...

I encounter an error in my JavaScript function indicating that it is not defined

let element = document.querySelector("#value"); let buttons = document.querySelectorAll(".btn"); buttons.forEach(function (button) { button.addEventListener("click", function(event){ console.log(event.currentTarge ...

Need help making switch buttons in react-native?

Using the library found at this link has been quite successful on my iPhone, but it does not display properly on Android. It appears as shown here. ...

Deliver properties to nested components following an asynchronous refresh

How can the updated props be passed to the Inputs component after completing an asynchronous operation? Is it possible to pass props to a child component without using connect in the Child component? class SignUp extends Component { componentDidMount(){ ...

Embedding JSON data in a GSP page

My goal is to transfer JSON data to a GSP page and present it in a table format. The expected JSON structure: { "data": [ [ "Tiger Nixon", "System Architect", "Edinburgh" ] ]} I attempted to achieve this with the following co ...

Enhance the dimensions of images on Tumblr

Is there a way to customize the width of a photo in HTML? I am having trouble changing the size of a photo set on Tumblr to be larger. I have tried researching it, but I don't understand where to place maxwidth:600px or if this is even the correct app ...

Difficulty adapting CSS using JavaScript

I am looking to adjust the padding of my header to give it a sleeker appearance on the page. I attempted to achieve this with the code below, but it seems to have no effect: function openPage() { var i, el = document.getElementById('headbar' ...

What is causing the loss of data when attempting to access an array field within an object?

So I've been grappling with this issue. I have a collection of objects, each containing string arrays and a string based on the following interface: export interface Subscription { uid: string; books: Array<string>; } The problem arises whe ...

Which approach is more efficient: storing fetched data in state or continuously re-fetching it using server functions in next.js 13?

Currently immersed in a project involving Next.js, I find myself questioning the most efficient data fetching method. In the latest version of Next.js, direct database data retrieval is enabled through server components. In contrast, older versions requi ...

Achieving dynamic HTML element addition through JavaScript while maintaining their record in PHP

There is an input box where the user specifies the number of new DIV elements to be added dynamically. This request is then sent to PHP via Ajax, where it prepares an HTML DIV with some inner input tags. Each DIV has a unique id attribute generated increme ...

Advantages and Disadvantages of Implementing Ajax for Form Validation

Exploring the benefits of validating forms with Ajax, I find it to be a valuable tool in preventing code redundancy. However, before making the switch, I am curious about any potential drawbacks compared to traditional JavaScript validation. While I have c ...

I am having trouble setting breakpoints in Google Chrome

For a while, I've been using Google Chrome to debug my JavaScript code without any issues. However, out of nowhere, I am no longer able to place breakpoints. When I click on the line number where I used to add breakpoints, nothing happens. Sometimes, ...

Troubleshooting problems with the guildMemberAdd event handler

As I continue on my journey with discord.js v12, I've encountered yet another issue with an event handler. While most events have been working fine so far, such as message or ready, I am currently facing a challenge with guildMemberAdd event. My goal ...

Why is TS1005 triggered for Redux Action Interface with an expectation of '=>'?

I'm finding it difficult to identify what's causing this issue, as shown in the esLint error from Typescript displayed in the screenshot below: https://i.stack.imgur.com/pPZa7.png Below is the complete code, which consists of actions for redux. ...

Navigating through an array of functions, some of which may return promises while others do not

Is there a way to efficiently iterate and execute an array of functions where some return promises, requiring the use of await, while most do not return promises, necessitating them to be set as async? for (let i = 0; i < this.steps.length; i++) { ...

Library with integrated Jquery functionalities

Hello again with another query. I recently came across a jQuery code that allows you to click on an entire table row (tr) to show/hide other rows (specified as .none). I managed to find the code and it works perfectly on JSFiddle. However, when I try to im ...

NodeJS - Subtract one array from another, while keeping all duplicates in place

Although the title may be misleading, how can you achieve the following: a = [1, 2, 2, 3, 3, 3]; b = [1, 2, 3]; a.subtract(b); I am aiming for a result of [2, 3, 3] instead of an empty array, as seen in other similar solutions. I want to remove only the ...

What is the best way to send the UserId from a payment API endpoint to a webhook endpoint?

insert image description hereI am currently integrating Firebase for user registration and authentication purposes. Additionally, I am incorporating the use of Stripe CLI in my project workflow. One specific requirement is to trigger certain events only fo ...

How come the new background isn't showing up when using styled-components?

My goal is to fetch an image URL from an API and utilize it as a background in my application, requiring the use of styled-components. Below is the code for my app: const API_KEY = `some key`; class App extends React.Component{ constructor() { ...

Converting wiki content to HTML with the help of PHP and JavaScript

Looking to convert wiki syntax to html? Check out the techniques discussed in this resource: Below is the source code of my php page that appears to be functioning correctly. Feel free to test it out yourself: <? if(!defined('DOKU_INC')) d ...