If I'm already displaying data that I have successfully fetched with SWR,
and then another fetch call fails (when revalidating the data),
I don't want to replace the data view with an error view.
Here's how to avoid that.
A component wrapped in React.forwardRef
normally expects to receive a ref from its parent component.
What if you want the component to have a ref
even if it doesn't receive one from its parent?
A <button> element defaults to type="submit"
which can cause accidental form submissions.
Make type="button" the default in your Button component
to make your life easier.
To handle internal link clicks when using dangerouslySetInnerHTML,
attach click event listeners to the rendered links.
In the listener, push the link to the browser history.
React's ecosystem is large,
which is a good thing:
lot's of great libraries to use.
But it's also a bad thing:
most of those libraries are compatible only with React.
HTM provides a transpiler-free alternative to JSX via tagged templates.
HTM has some limitations,
but can be used in browsers
and can be good for smaller projects.
A common solution is to scroll to top every time the page changes.
That's incorrect:
the page should be scrolled to top only when navigating to new pages,
not when navigating back or forward.
Normally you would use one-way data binding in React apps:
parent components own data and pass it to children.
You can mimic two-way data binding with a custom hook.
A multi-site React project has likely two kinds of components:
common components and site-specific components.
There are a few ways to handle site-specific logic in common components.
JSX is just JS under the hood.
Hyperscript is like that JS,
but better.
Example:
h('a.link', { href }, 'Click me')
is nicer than
<a className="link" href={href}>Click me</a>,
right? Right?!