Closed pollock83 closed 2 years ago
@pollock83
https://codesandbox.io/s/elastic-browser-bhs8lu?file=/src/App.tsx
I made a demo similar to your code, but it works.
const numPics = data.allFile.edges.length;
console.log(numPics);
I think it's like a change in numPics
.
Did the value change before the button was pressed and after the button was pressed?
A change in this value causes duplication of key values. Check it.
@daybrush Thanks for your reply! :)
Unfortunately it doesn't seem to be a change in numPics
. When I remove numPics
and change the code to just get 10 items as a hard-coded value, the error still occurs...
Could it be something to do with GatsbyJS?
My current solution to workaround this issue is to wrap my Gallery component in a React.memo()
to prevent it rerendering. This seems to work, but obviously isn't an ideal solution...
@pollock83
There is a function called Item
in GalleryComp.
Since Item
is changed for every rendering, the Item is newly rendered.
Either move it out or wrap the Item with useMemo.
@daybrush That seems to have fixed it! Thanks for the help!
Description
I'm using react-infinitegrid to create a Masonry grid of image components to form a gallery on my GatsbyJS website. I would like to be able to show a lightbox containing a full screen image when one of the images in the gallery is clicked.
I am running into an issue where when I show/hide a component using selective rendering, all of the
<div>
components within the gallery lose their styling when a component is shown/hidden. This means that the grid breaks and I am left with just a long column of images. I have tested this also with just showing/hiding a<p>
component on the page and experience the same behaviour.Please see the video of the behaviour below. Notice that when I click my 'Test' button, and the 'Hello!' component is shown, all of the
<div>
components containing the images lose their position styling (you can see this update in the chrome developer view on the right).Video: https://imgur.com/a/3PpYr6Z
Before:
After:
Page.tsx:
Gallery.tsx:
Thanks!