3 ms·
I'm disappointed that this isn't talked about, even when someone explicitly asks: You can't use JS to iterate over, store or otherwise work with the output of t
by SebastianKra 3y ago
I'm disappointed that this isn't talked about, even when someone explicitly asks: You can't use JS to iterate over, store or otherwise work with the output of the templating language.
For example:
const cells: Record<string, ReactNode> = { a: "hello world", b: <>hello <b>world</b></>, c: <Icon src="world.png" />}
The closest you could get in Svelte, is creating three new components (3 entire files), which are then rendered using `<svelte.component this={HelloWorldComponent} />`.
This becomes a problem, when you build composed components that decide their layout based on logic thats too complex to express in CSS or Sveltes templating system.
For example:
- A component for tabbed navigation that automatically becomes a sidebar on desktop.
- React Router defining its entire navigation tree [1]
- Ant.Design defining the columns of the table, where you can trivially supply a short callback to render a cell [2]
[1]: https://reactrouter.com/en/main/routers/create-browser-router https://reactrouter.com/en/main/routers/create-browser-route...
[2]: https://ant.design/components/table https://ant.design/components/table