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

100
Views
not adding css for changing id - reactjs

I'm creating a popup in React js and have a div with a changing id based on a boolean gameOver.winner Right now I have set gameOver.winner to true.

import React, { useContext } from 'react'
import { AppContext } from '../../../App'
import './GameOver.css'

const GameOver = () => {
    const { currAttempt, setCurrAttempt, grid, setGrid, gameOver, setGameOver} = useContext(AppContext)
    console.log(gameOver.winner)
    return (
        <div className="gameOver" ** id={gameOver.winner}> **
            <div className="gameOverInner">
                <h1>Game Over</h1>
                <h2>{gameOver.winner ? "You Win!" : "You Lose!"} - {currAttempt.currRow}</h2>
            </div>
        </div>
    )

}
export default GameOver

In GameOver.css I am calling this id

.gameOver[id=true]{
    top: 0;
    left: 0;
    width: 25%;
    background-color: rgb(41, 41, 41);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2;
}

However, my output has no styling to it.

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

0

If gameOver.winner is a boolean, then it's not going to output a <div id="true"> node to the DOM. React doesn't accept boolean values for the id prop on intrinsic html elements (you should see an error in the browser console regarding it). If you want to add special styling to your div based on a boolean value, I'd suggest adding a class to it when gameOver.winner is true.

<div className={`gameOver ${gameOver.winner ? 'winner' : ''}`}>

Then in your css file you can target it with the selector .gameOver.winner.

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!