Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

71
Views
Css class is not implemented in the React App using Props

Below is the code for components:

Card Component:

import "./Card.css";

function Card(props) {
  const classes =
    "card" +
    props.className; /* css classes of "ExpenseItem Component" and "Card component in "classes" */

  return <div className={classes}>{props.children}</div>;
}

export default Card;

ExpenseItem Component:

import ExpenseDate from "./ExpenseDate";
import Card from "./Card";
import "./ExpenseItem.css";

function ExpenseItem(props) {
  return (
    <Card className="expense-item">
      <ExpenseDate date={props.date} /> /*ExpenseDate component imported to show date from another component*/
      <div className="expense-item__description">
        <h2>{props.title}</h2>

        <div className="expense-item__price">${props.amount}</div>
      </div>
    </Card>
  );
}

export default ExpenseItem;

you went through the snippets above, now the problem i'm facing is that when I use the Card component in the ExpenseItem Component to wrap the component inside the Card JSX tags, it breaks the CSS and does not use the CSS classes i'm implementing by using the const classes variable in the Card component, but if I use the div instead of Card in ExpenseItem the component works fine. Below I'm attaching both the Screenshots as well..

With div tags: enter image description here

With Card Tags:enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Please put a space after the "card" class so that all the class names are separated by space.

const classes = "card " + props.className;

about 4 years ago · Juan Pablo Isaza Report

0

Your classes variable needs a space in the string

e.g.

const classes = "card " + props.className
// or
const classes = `card ${props.className}`
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!