SolidJSS
SolidJSโ€ข2y agoโ€ข
5 replies
Mimikku

memo with dynamic props pass

am I doing something heavily retarded?
I find myself doing this pattern a lot to enforce that props item is subscribed to
export interface AccordionProps {
  items: AccordionItem[];
  class?: string;
}

const Accordion = (props: AccordionProps) => {
  const items = createMemo(
    on(
      () => props.items,
      items => assignPaths(items),
    ),
  );
  
  return (
    <ul class={cx('flex flex-col h-full overflow-auto px-2', props.class)}>
      <For each={items} children={Item} />
    </ul>
  );
};

Or should I do something entirely else?

  const items = createMemo(
    on(
      () => props.items,
      items => assignPaths(items),
    ),
  );

It just seems "Funny"
I mean I could also use
const Accordion = (props: AccordionProps) => {
  return (
    <ul class={cx('flex flex-col h-full overflow-auto px-2', props.class)}>
      <For each={assignPaths(props.items)} children={Item} />
    </ul>
  );
};
Was this page helpful?