react-plock icon indicating copy to clipboard operation
react-plock copied to clipboard

Possibile to get the real index (idx) ?

Open tahola opened this issue 2 years ago • 1 comments
trafficstars

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

tahola avatar Apr 25 '23 03:04 tahola

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?

askides avatar Sep 22 '23 08:09 askides

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.

github-actions[bot] avatar Apr 23 '24 18:04 github-actions[bot]

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

crapthings avatar May 17 '24 11:05 crapthings