Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

101
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda