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

170
Views
Is there a way to change the color/state of a button in react depending on how each state?

I am trying to change the color of the button, depending on "each state". For e.g, if the state is active, the colour of the button would be red. otherwise it would be blue. Does anyone have an idea on how to implement that on react? Additionally, i would like to have different state, instead of just two. e.g. active, inactive, activating, pending etc.

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

0

is this what you're looking for ?

import { useState } from "react";

export default function App() {
  const [state, setState] = useState("active");

  return (
    <div className="App">
      <button style={{ color: state === "active" ? "#F00" : "#00F" }}>
        click me
      </button>
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza Report

0

To make the bullet a dot, you can set border-radius into the style. Personally, I suggest you do this on a separate css file rather than directly in the attributes.

So you can have a style.css file

.App button {
    border-radius: 100%; // for a circle
}

And in your main js file

import { useState } from "react";
import './style.css'; // Or what ever path style.css is in

export default function App() {
  const [state, setState] = useState("active");

  return (
    <div className="App">
      <button style={{ color: state === "active" ? "#F00" : "#00F" }}>
        click me
      </button>
    </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!