inline conditional style in react js

3.8k views Asked by At

I am new in reactjs and I want to write inline if that work when I have 1 column make it center

  const [boxViewWidth, setBoxViewWidth] = useState(0)


<div
          style={{
            ...style,
            columnCountBox: 1 ? right : (boxViewWidth / columnCountBox) * (columnIndex % columnCountBox) ,'calc (50% - 150px / 2)'
          }}
        >

1

There are 1 answers

0
Hans Murangaza DRCongo On

To make inline statement, quick is

var a=1; var b=2;
<div style={{column: a === b ? "if true style" : "else style"}}></div>
<div style={a === b ? {column: "if true style"} : {column: "if false style"}}></div>

or with only one statement:

<div style={{column: a === b && "value if true"}}></div>