JSFiddle - React, Tailwind, and code Playground

HTML

<div id="menu"></div>
<div id="body"></div>

CSS

.menuFixo {
    position: fixed;
    top: 0px;
    background-color: #ccf;
}
* {
    padding: 0px;
    margin: 0px;
}
div {
    border: 1px solid blue;
    width: 100%;
}
#menu {
    height: 50px;
}
#body {
    height: 2000px;
}

JavaScript

(function () {
    var menu = document.getElementById('menu');
    window.addEventListener('scroll', function () {
        if (window.scrollY > 0) menu.classList.add('menuFixo');
        else menu.classList.remove('menuFixo');
    });
})();