Skip to content

Proposal: switch from HoC to render prop (or function as children) #75

Description

@developerdizzle

Thinking about the possibility of replacing the HoC technique with the render prop technique.

The syntax would go from:

const MyVirtualList = VirtualList()(MyList);

return (
  <MyVirtualList
    items={myBigListOfItems}
    itemHeight={100}
  />
);

to

return (
  <VirtualList
    items={myBigListOfItems}
    itemHeight={itemHeight}
    renderVirtual={({ items, style} => (
      <ul style={style}>
        {items.map(item => (
          <li key={`item_${item.id}`} style={{height: itemHeight}}>
            Lorem ipsum dolor sit amet
          </li>
        ))}
      </ul>
    ))}
    />
);

Alternatively it could be function as children:

return (
  <VirtualList
    items={myBigListOfItems}
    itemHeight={itemHeight}
    >
    {({ items, style } => (
      <ul style={style}>
        {items.map(item => (
          <li key={`item_${item.id}`} style={{height: itemHeight}}>
            Lorem ipsum dolor sit amet
          </li>
        ))}
      </ul>
    ))}
  </VirtualList>
);

Any thoughts?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions