SolidJSS
SolidJS3y ago
guido

How to have reactive getters on each element?

Let's say I have a
createStore
, and I want each element to have a getter, how should I go about this?
I asked chat gpt, and he proposed this.

const [state, setState] = createStore([
  { name: 'John', age: 30 },
  { name: 'Mary', age: 25 },
  { name: 'Bob', age: 40 },
]);

const filteredState = createComputed(() =>
  state.map((item) => ({
    ...item,
    get filteredName() {
      return item.name.toLowerCase().startsWith(nameFilter().toLowerCase());
    },
  }))
);


I think this looks ok enough, do you guys agree? Is there an alternative that lets you include getters right into the data I pass to
createStore
?
Was this page helpful?