|
|
|
|
|
by iyc_
1575 days ago
|
|
> In React, we render lists by using regular JavaScript idioms like loops, arrays, and array methods like map. However in Solid.js, much like traditional templating languages, we get a construct like <For> that reinvents a concept that's already in the language. I had/have your bias, but from playing with it I found a couple things: 1) Like React, you can swap out the template feature for a function call (or subcomponent).
e.g. instead of return (
<button...>
...
</button>
<For each={state.todos}>
...
);
you can use functions and loops: function displayTODOs<T>(todos: T[]): any {
let arr: any[] = [];
for(let [i, todo] of todos.entries()) {
const { done, title } = todo;
let elem = (/\* JSX \*/);
arr.push(elem);
}
return arr;
}
...
return (
<button ...>
</button>
{displayTODOs(state.todos)}
);
2) Even with my bias, I must admit I found the `<For...` syntax to be surprisingly easy to read and fast to eye-parse; much more so than other 'templating' (using your term) languages/macros/syntax I've used over the years. |
|