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

332
Views
How to add className to component in react?

I have a navbar component that I created for react. When I call this component on different pages, I need to change the classNames.

For example : I want my "" component to have a different class on one page and a different class on another page.

const ServicesCiso = () => {
return (
    <div className="hero">
        <NavBar/>
        <div className...

How can i add className in this code ?

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

0

You can pass the className as props to this component and pass the preferred className on the page you are rendering it

const ServicesCiso = ({ className }) => {
return (
    <div className={className}>
        <NavBar/>
        <div className...
<ServicesCiso className="my-class-name" />
about 4 years ago · Juan Pablo Isaza Report

0

You should pass the className from out side to your component via props however you also need a default class in init case

I have suggestion this library https://www.npmjs.com/package/classnames ( combine classes )

example

View
   - ServicesCiso.js
   - ServicesCiso.css
import ./ServicesCiso.css;
import cn from('classnames');

const ServicesCiso = (props) => {
   const {className} = props;

   return (
     <div className={cn('hello', className}}>
     </div>
   )
}
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!