effector / reflect

Easily render React components with everything you love from ☄️ effector.

Home Page:https://reflect.effector.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why list.bind and list.mapItem are required?

Kelin2025 opened this issue · comments

Hi! First of all, great library! I was doing something like that in the past, but hadn't time to make it to complete library-like thing

But I have a question about list method

The problem

I wanted to make a simple like like this:

const AddButtons = list({
  source: $leafSchemas,
  view: (leafSchema) => {
    return (
      <button
        onClick={() =>
          leafAdded({ type: leafSchema.type, name: leafSchema.name })
        }
      >
        Add {leafSchema.name}
      </button>
    );
  },
  getKey: (leafSchema) => leafSchema.type,
});

But, according to types, we should add mapItems and bind options
image
Would really like to have them optional. bind is not needed in most of my cases, mapItems is good to have but we could have a default behavior "to pass a whole item"

On a side note...

If both options will be optional, we could also add an additional simpler notation:

const AddButtons = list($leafSchemas, leafSchema => {
  return <button>...</button>
})

In Forest we have list method and it works like this: click

commented

Because you don't need list, just use useList

Because you don't need list, just use useList

Meh

const PostsList = list($postsList, post => {
  return <PostItem post={post} />;
});

or even

const PostsList = list({
  source: $postsList,
  view: PostItem
})

vs.

const PostsList = () => {
  return useList($postsList, post => {
    return <PostItem post={post} />
  });
};
  • This is a bit more code for the same thing
  • You can't do useEffect in useList (you can in list.hooks.mounted)
  • I also don't like having inconsistency in components declarations. I wanted to make most of the components declared by using reflect API, and just because of the problem described - it doesn't look good

@Kelin2025
bind and mapItem are now optional for list in the latest release of @effector/reflect - version 7.1.1 🎉
It will work only if type of source item is matching view props