JSFiddle - React, Tailwind, and code Playground

HTML

<div id="block" style="display:none;"></div>

<input type="checkbox">

CSS

#block{
  padding:20px;
  background:#000;
}

JavaScript

const block = document.getElementById('block');
const checkbox = document.querySelector('input[type="checkbox"]');
let timer = null;

checkbox.addEventListener('change', function () {
	const isChecked = this.checked;
  
  if (isChecked) {
    block.style.display = 'block';

    timer = setTimeout(() => {
      block.style.display = 'none';
    }, 5000);
  } else {
  	block.style.display = 'none';
    
    if (timer) {
  		clearTimeout(timer);
      timer = null;
    }
  }
})