score:0
Accepted answer
you could try a ternary operator to set conditional classes.
:class="{{totalnetworkscore ? 'green' : 'red'}}"
in css:
.green {
background: green;
}
.red {
background: red;
}
score:0
you can use the @emotion/core library and do something like this:
import { css } from "@emotion/core";
import react from "react";
checknegative = counter => {
if (counter) {
return css`
background: green;
`;
}
};
class component extends react.component {
state = { counter: -1 };
render() {
return <div css={checknegative(this.state.counter)}>some text</div>;
}
}
export default component;
Source: stackoverflow.com
Related Query
- How to change background color when a variable is negative?
- How to change navbar background color in react when I scroll
- how to change background color when I click the button using react hooks
- How to change the background or text color of the countdown timer to green when there is only 30 minutes remaining to finish the countdown?
- How can I change the background color of elements when they're clicked?
- How Do I make my Nav Menu option change color or background when I click on it using Javascript only?
- When I click the button, I want to change the page background color to another color, not black, how can I do it?
- How to change button background color when I click the button in React using Hooks
- How to change background color of react native button
- How do I change the background color of the body?
- How to change background color of a selected ItemList Material-Ui
- How do I change the background color of a selected react-bootstrap ToggleButton?
- Material UI Toggle Button - can't change background color when selected
- How to change the text color and background color of ant-tooltip component
- How to change the selected table row background color with React
- How to change background color of a reusable component in ReactJS?
- How to change the background color of an ant.design InputNumber?
- How to change the background color of a parent component from inside a child component in react, gatsby
- How to change the background color in semantic ui react?
- ReactJS 7 - How to conditionally change the background color of table cell only (not the row) based on its value?
- How to change header background color in react based on location
- How to change the background color of chart in amcharts
- How to change the background and text color within button using button onClick in React JS
- How do I change the default background color of notistack in MUI v5?
- How to change the background color of MUI Menu Popover of TextField with select property?
- How to change font color based on background color using reactJs
- How to change color when Item of paginate is active in ReactJS?
- How to change background color of button using react
- Material UI styled() utility - How to recursively change highlighted text background color
- in a map function, i want to set a state which let me change the background color when i click on a div
More Query from same tag
- ReactJS localstorage.getItem is not working
- How to write and access function in React stateless components
- Return just single Object instead of Array in NEXT.JS and MongoDB
- Using react-router to switch between pages but my props aren't displaying, is this a router version issue?
- React multiple checkbox with selected values set
- Why does the handleClick method in my component seem to loop?
- React.js + bootstrap-table working only on first load, but transitions break the table
- How to test `onChange` event with range input in Jasmine/React
- React functional component : can we setState on form load event
- Sorting array of objects in MUI cards depending on social media
- How to rename project react native
- How React Can Change Components With Key Attribute?
- React & Redux CRUD: Displaying a single item not working
- React (Refs to Component): Unable to use "ref" with "conditional rendering"
- What's the difference between Enzyme simulation in shallow and mount wrappers?
- Get output from user typed code JavaScript
- How to deploy my React-App to github User Pages
- Have I configured my endpoints correctly for my react and node app?
- Switch CSS classes with state
- Material-UI SelectField onChange doesnt work
- How to fetch form with file and recieve it on net core?
- Trying to pass onChange function as props to GrandChlidren result into TypeError: this is undefined
- a better way to map a list in js
- Problem updating object in state with values from four different select tags
- Error: Error parsing triggers while deploying cloud functions - Firebase
- Material UI input field looking weird
- PlayFramework with Scala, WebJars, ReactJS and RequireJS?
- Nested array in object returns 'undefined' when accessing in JSX
- How to use mutations in react-apollo-hooks and formik?
- ReactJS - Pass parameter from blade to JSX