r/reactjs • • 6h ago

Show /r/reactjs Treflex demo – live hot-swap between React and Solid

Thumbnail
youtu.be
0 Upvotes

Live swap demo: https://tgoh.github.io/treflex/swap/

Treflex is something I've been working on for the past few years: a headless state engine. Your app's logic (state, async work, timers, connections) runs on its own, and React or Solid is just a view you plug into it. In the demo you can swap between them while everything's running, and the app doesn't notice.

Why: AI agents write a lot of front-end code now, and async is where they slip: races, double starts, work that dies on unmount. With the logic out of components, those mistakes get caught. It's tested without rendering, a test controls the order async calls answer in, and the runtime and lint rules fail with errors that say what to change.

const FishReceiver = receiver<IFish>("FishReceiver")({
  *"Fish/Swim"(fish) {
    fish.X = (yield* random()) * 100;
    fish.Y = (yield* random()) * 100;
  }
});

function* addFish(school: ISchool) {
  const fish = yield* entity(newFish());
  school.Fish.push(fish);

  // The timer belongs to the fish, not a component
  yield* startTimer(fish, "Fish/Swim", FishReceiver, 3000);
}

function* releaseSchool(tank: IAquarium, schoolId: string) {
  // Every fish in the school stops swimming. No cleanup needed.
  tank.Schools = tank.Schools.filter((s) => s.$Id !== schoolId);
}

It's 0.2 and still changing. Questions and feedback would be greatly appreciated.


r/reactjs • • 13h ago

Resource A few SVG attribute gotchas that show up when you drop an icon into JSX

0 Upvotes

I've had this bite me more than once: I paste an SVG from a design tool into a React file, and the component looks fine until React complains about the attributes.

React does not use SVG's XML names. On a normal icon the pairs are:

// SVG
<rect class="icon" fill-rule="evenodd" stroke-width="2" stroke-linecap="round" />

// JSX
<rect className="icon" fillRule="evenodd" strokeWidth={2} strokeLinecap="round" />

A few other ones that come up a lot: stroke-linejoin → strokeLinejoin, clip-path → clipPath, clip-rule → clipRule, stop-color → stopColor. And a style attribute has to become a JS object, not a string:

// SVG
<rect style="fill:#ff00aa" />

// JSX
<rect style={{ fill: "#ff00aa" }} />

The part that surprised me is that a find-and-replace on the raw file is the wrong tool for this.

If a <text> label happens to contain the characters stroke-width, a regex will rewrite the label too. The attribute on the element should change. The text inside the graphic should stay as text.

viewBox is another one people over-correct. React already accepts viewBox on an <svg>, so it should not be rewritten to viewbox. xmlns, path d data, and fill="url(#id)" references should stay as they are (assuming you haven't stripped the defs).

Two other gotchas, if you are cleaning the file up at the same time:

  • Turning solid fills into currentColor is useful when you want the icon to inherit color from CSS. It can also rewrite gradient stops, so the preview can look different from the original. I leave that off until I want it.
  • The same for an SVGO pass. If you only wanted the attribute rewrite, run that first and turn cleanup on later.

This is a React JSX/TSX issue. Vue and Svelte single-file components keep class and stroke-width in the template.

I built a small in-browser converter while working through this: https://www.svgtoreact.com — it uses SVGR so the file is parsed, not search-replaced, and the SVG stays on your device. Happy to answer questions if any of this is unclear.


r/reactjs • • 9h ago

Kivu UI: React components where your Tailwind classes always win

0 Upvotes

I built a React component library that doesn't fight Tailwind.
Component styles live in u/layer components, so any className you pass overrides them.
No tailwind-merge, no !important.

  • Zero runtime dependencies
  • Plain CSS variables, no CSS-in-JS
  • Accessible (keyboard navigation, ARIA, native <dialog>)
  • 40+ components, React 18 and 19, TypeScript

npm install kivu-ui

Docs: https://kivu-ui.vercel.app/