You can try like his
<button
onMouseDown={() => setActive(true)}
onMouseUp={() => setActive(false)}
onMouseLeave={() => setActive(false)}
style={{
backgroundColor: active ? '#fff' : '#000',
color: active ? '#000' : 'fff'
}}
>
Button Label
</button>