When I try to change colour depends on the count it show’s the error TypeError: Cannot read property ‘style’ of null

You can achieve what you wanted this way.

return(
    <div className='container_new'>
        <h1>Counter</h1>
        <span id='value' style={{ color: Count === 0 ? 'black' : 'white' }}>{Count}</span>
        <div>
            <button className="btn decrease"  onClick={handleDecrement} >decrease</button>
            <button className="btn reset" style={{color: 'black'}} onClick={() => handleReset()}>reset</button>
            <button className="btn increase" onClick={() => handleIncrement()}>increase</button>
        </div>
    </div>
)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top