askides / react-plock

The 1kB Masonry Grid for React.
https://react-plock-with-nextjs.vercel.app
MIT License
493 stars 10 forks source link

Possibile to get the real index (idx) ? #35

Closed tahola closed 4 months ago

tahola commented 1 year ago

Hello,

is it possible to get the real index in the render ?

const items = [...imageUrls];

  return (
    <Masonry
      items={items}
      config={{
        columns: [1, 2, 3],
        gap: [24, 12, 6],
        media: [640, 768, 1024],
      }}
      render={(item, idx) => (
        <img key={idx} src={item} style={{ width: "100%", height: "auto" }} />
      )}
    />
  );

Here idx is the number of the row, is there a proper clean way to know that I am displaying third item ? Like "index" in a map.

Thank you, and thanks a lot for your work

askides commented 12 months ago

Hello!

I need to reasonate about this issue, but i think it can be affordable, the idea would be passing the entire item on the render method, and let the final user decide the prop to use.

Something like this:

return (
  <Masonry
    render={(item) => (
      <img key={item.id} src={item.source} {{ ...others }} />
    )}
  />
);

What do you think about?

github-actions[bot] commented 4 months ago

This issue has been automatically closed due to inactivity. If you still have further updates, please feel free to reopen or create a new issue.

crapthings commented 4 months ago

for now u can only map index before it get into the plock

https://github.com/askides/react-plock/blob/main/libs/react-plock/src/Plock.tsx#L80