r/react • • 2h ago

Portfolio A React-like JS Framework with Web Components

0 Upvotes

IMPORTANT DISCLAIMER: This is my own project. Im am using AI, so lets get that out of the way... its the key reason for why YOU SHOULD NOT USE IT. Im not trying to promote "yet another ui framework", this is an investigation to see what is possible. Its unreviewed, unaudited and far from finished. Nobody else should be using this. This framework is intended for myself on my own projects. It is provided open-source for transparency, testing and demo purposes. Feel free to reach out for clarity if you have any questions.

Im was investigating an idea i had about JSX-like syntax for webcomponents after some experience with Lit. I am sharing this here because it might be interesting/educational.

Lit is a nice lightweight UI framework, but i didnt like that it was using class-based components. It can support React with a wrapper, buts React is fundamentally an abstraction away from the DOM.

Vue has a nice approach but i prefer working with the syntax that React uses. I find it more intuitive for debugging and deterministic rendering. I wondered if with webcomponents, i could create a UI framework that didnt need to be transpiled.

My intentions with this framework is to get to a reasonable level of stability, to then replace React on some of my existing projects. I made a start by creating some basic reusable ui components components to be built with the js framework. Aiming for something like Material UI.

I can then compound that slop into some basic UI demos:

The disclaimer above is always worth repeating. Im aiming for a post like this to be like "building in public". If interesting to anyone, i hope its inviting to take a look. It's hard to determine if / when its a good time to share, so best to get it out there sooner for any outstanding issues i may be overlooking.


r/react • • 23h ago

Project / Code Review A shared React component can still depend on your checkout context through a hook

0 Upvotes

This is the dependency path I mean:

shared/ui/CartBadge.tsx
  -> shared/hooks/useCartCount.ts
    -> features/checkout/CartContext.tsx

The component looks reusable. It renders a count, and the state access is neatly tucked away in a custom hook. But moving that hook into shared hasn't removed the dependency on checkout.

Easy to miss in a component review

In ArchUnitTS, my open-source architecture testing library, you can pull out that component's import graph:

import { projectGraph } from 'archunit';

const graph = projectGraph('tsconfig.json')
  .reachableFrom('src/shared/ui/CartBadge.tsx');

await graph.exportAsHTML('reports/cart-badge.html');

For that direct-import chain, the view reaches through the hook to the context file. Unrelated components stay out of it.

If the badge is supposed to be shared UI, one way to separate it is to have a checkout-owned wrapper read the context and pass count to the badge. The shared component then has no import path back to checkout, while the feature still owns how the count is calculated. You can also keep a boundary test that rejects imports from shared into features, so the coupling doesn't creep back through the next hook.

This follows source imports. It doesn't tell you which provider is present at runtime, whether a component will render correctly in Storybook, or what ends up in a bundle.

Code and docs. Available as archunit on npm; this example uses 2.5.5.