TheBigSasha / tbsui-ssr

CSS only React component library, built for static sites using NextJS or Gatsby.
https://thebigsasha.github.io/tbsui-ssr/
MIT License
0 stars 0 forks source link

Hooks for programatic Navbar control #28

Open TheBigSasha opened 1 year ago

TheBigSasha commented 1 year ago

Export a hook useNavbarControl() which exposes functions that allow you to set and observe the open state of the navbar.

To do this

Suggested usage

import { useNavbarControl } from "tbsui-ssr";
...
const [isNavbarOpen, setNavbarOpen] = useNavbarControl();
TheBigSasha commented 1 year ago

Q: Why wrap CSS state in React state? A: Using pure CSS improves performance and SSR capabilities, this solution is super friendly to lazy loading in React after the page, because all navbar logic is loaded in HTML and CSS alone, then the heavier Javascript code will react to the CSS state, but only once whatever JS will consume the navbar state is loaded too. Basically, it's for either lighter pages which don't need this hook, or pages using this hook before their js is loaded in to benefit in performance.