SetState not re-rendering and galleries getting mixed The Next CEO of Stack OverflowReactJS - Does render get called any time “setState” is called?React “after render” code?Set focus on input after renderReactjs setState() with a dynamic key name?React: How do I update state.item[1] on setState? (with JSFiddle)Can you force a React component to rerender without calling setState?Why calling react setState method doesn't mutate the state immediately?React - uncaught TypeError: Cannot read property 'setState' of undefinedUpdating an object with setState in ReactReact Simple Re-Rendering - setState is not re-rendering?

Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?

How can I replace x-axis labels with pre-determined symbols?

That's an odd coin - I wonder why

How can a day be of 24 hours?

Do I need to write [sic] when including a quotation with a number less than 10 that isn't written out?

Arrows in tikz Markov chain diagram overlap

Raspberry pi 3 B with Ubuntu 18.04 server arm64: what pi version

Is it OK to decorate a log book cover?

Salesforce opportunity stages

What steps are necessary to read a Modern SSD in Medieval Europe?

Compensation for working overtime on Saturdays

Why doesn't Shulchan Aruch include the laws of destroying fruit trees?

Planeswalker Ability and Death Timing

A hang glider, sudden unexpected lift to 25,000 feet altitude, what could do this?

Is there a rule of thumb for determining the amount one should accept for a settlement offer?

Small nick on power cord from an electric alarm clock, and copper wiring exposed but intact

Ising model simulation

My boss doesn't want me to have a side project

What difference does it make matching a word with/without a trailing whitespace?

Find the majority element, which appears more than half the time

How seriously should I take size and weight limits of hand luggage?

Car headlights in a world without electricity

How to pronounce fünf in 45

Incomplete cube



SetState not re-rendering and galleries getting mixed



The Next CEO of Stack OverflowReactJS - Does render get called any time “setState” is called?React “after render” code?Set focus on input after renderReactjs setState() with a dynamic key name?React: How do I update state.item[1] on setState? (with JSFiddle)Can you force a React component to rerender without calling setState?Why calling react setState method doesn't mutate the state immediately?React - uncaught TypeError: Cannot read property 'setState' of undefinedUpdating an object with setState in ReactReact Simple Re-Rendering - setState is not re-rendering?










0















I am working on a custom react project and I have a problem that a wrong array of images is showing when a component should be rerendered, I am not sure what the real issue is but I think I might be missing a rerendering somewhere, i will try to explain as best as i can below please seek more info if you need it, also try to bear with me there's a link at the end :)



NOTE: gallery component is where you choose the gallery and ContainerPhotography is the one where image arrays that don't work are shown



this is the JSON object that i am using in state



 fotografije: [

"naslov": "Sculptures",
"id": "f00",
"brSlika": "10 image Gallery",
"naslovnaSlika": "http://lanapavkov.com/content/img1.png",
"naslovKlasa": "sculptures_naslov",
"slikeUGaleriji": ["http://lanapavkov.com/content/skulpture/skp0.jpg", "http://lanapavkov.com/content/skulpture/skp1.jpg", "http://lanapavkov.com/content/skulpture/skp2.jpg", "http://lanapavkov.com/content/skulpture/skp3.jpg", "http://lanapavkov.com/content/skulpture/skp4.jpg", "http://lanapavkov.com/content/skulpture/skp5.jpg", "http://lanapavkov.com/content/skulpture/skp6.jpg", "http://lanapavkov.com/content/skulpture/skp7.jpg", "http://lanapavkov.com/content/skulpture/skp8.jpg", "http://lanapavkov.com/content/skulpture/skp9.jpg"],
"slikaKlasa": "sculptures"
,
"naslov": "Captions",
"id": "f01",
"brSlika": "16 image Gallery",
"naslovnaSlika": "http://lanapavkov.com/content/una_gallery.png",
"naslovKlasa": "captions_naslov",
"slikeUGaleriji": ["http://lanapavkov.com/content/captions/cpt1.jpg", "http://lanapavkov.com/content/captions/cpt2.jpg","http://lanapavkov.com/content/captions/cpt3.jpg", "http://lanapavkov.com/content/captions/cpt4.jpg", "http://lanapavkov.com/content/captions/cpt5.jpg", "http://lanapavkov.com/content/captions/cpt6.jpg", "http://lanapavkov.com/content/captions/cpt7.jpg", "http://lanapavkov.com/content/captions/cpt8.jpg", "http://lanapavkov.com/content/captions/cpt9.jpg", "http://lanapavkov.com/content/captions/cpt10.jpg", "http://lanapavkov.com/content/captions/cpt11.jpg", "http://lanapavkov.com/content/captions/cpt12.jpg", "http://lanapavkov.com/content/captions/cpt13.jpg", "http://lanapavkov.com/content/captions/cpt14.jpg", "http://lanapavkov.com/content/captions/cpt15.jpg", "http://lanapavkov.com/content/captions/cpt16.jpg",],
"slikaKlasa": "captions"
,
"naslov": "Eva",
"id": "f02",
"brSlika": "9 image Gallery",
"naslovnaSlika": "http://lanapavkov.com/content/Eva_prez.png",
"naslovKlasa": "eva_naslov",
"slikeUGaleriji": ["http://lanapavkov.com/content/eva/1.jpg", "http://lanapavkov.com/content/eva/2.jpg", "http://lanapavkov.com/content/eva/3.jpg", "http://lanapavkov.com/content/eva/4.jpg", "http://lanapavkov.com/content/eva/4(1).jpg", "http://lanapavkov.com/content/eva/5.jpg", "http://lanapavkov.com/content/eva/6.jpg", "http://lanapavkov.com/content/eva/7.jpg", "http://lanapavkov.com/content/eva/8.jpg", "http://lanapavkov.com/content/eva/10.jpg", "http://lanapavkov.com/content/eva/11.jpg", "http://lanapavkov.com/content/eva/12.jpg", "http://lanapavkov.com/content/eva/13.jpg", "http://lanapavkov.com/content/eva/14.jpg", "http://lanapavkov.com/content/eva/15.jpg", "http://lanapavkov.com/content/eva/16.jpg", "http://lanapavkov.com/content/eva/17.jpg", "http://lanapavkov.com/content/eva/18.jpg", "http://lanapavkov.com/content/eva/19.jpg", "http://lanapavkov.com/content/eva/20.jpg", "http://lanapavkov.com/content/eva/21.jpg", "http://lanapavkov.com/content/eva/22.jpg", "http://lanapavkov.com/content/eva/23.jpg", "http://lanapavkov.com/content/eva/24.jpg"],
"slikaKlasa": "eva"
,
"naslov": "Exposures",
"id": "f03",
"brSlika": "19 image Gallery",
"naslovnaSlika": "http://lanapavkov.com/content/street_gallery_1.png",
"naslovKlasa": "exposures_naslov",
"slikeUGaleriji": ["http://lanapavkov.com/content/exposures/exp1.JPG", "http://lanapavkov.com/content/exposures/exp2.JPG", "http://lanapavkov.com/content/exposures/exp3.JPG", "http://lanapavkov.com/content/exposures/exp4.JPG", "http://lanapavkov.com/content/exposures/exp5.JPG", "http://lanapavkov.com/content/exposures/exp6.JPG", "http://lanapavkov.com/content/exposures/exp7.JPG", "http://lanapavkov.com/content/exposures/exp8.JPG", "http://lanapavkov.com/content/exposures/exp9.JPG", "http://lanapavkov.com/content/exposures/exp10.JPG", "http://lanapavkov.com/content/exposures/exp11.JPG", "http://lanapavkov.com/content/exposures/exp12.JPG", "http://lanapavkov.com/content/exposures/exp13.JPG", "http://lanapavkov.com/content/exposures/exp14.JPG", "http://lanapavkov.com/content/exposures/exp15.JPG", "http://lanapavkov.com/content/exposures/exp16.JPG", "http://lanapavkov.com/content/exposures/exp17.JPG", "http://lanapavkov.com/content/exposures/exp18.JPG", "http://lanapavkov.com/content/exposures/exp19.JPG", "http://lanapavkov.com/content/exposures/exp20.JPG", "http://lanapavkov.com/content/exposures/exp21.JPG", "http://lanapavkov.com/content/exposures/exp22.JPG", "http://lanapavkov.com/content/exposures/exp23.JPG", "http://lanapavkov.com/content/exposures/exp24.JPG", "http://lanapavkov.com/content/exposures/exp25.JPG", "http://lanapavkov.com/content/exposures/exp26.JPG", "http://lanapavkov.com/content/exposures/exp27.JPG", "http://lanapavkov.com/content/exposures/exp28.JPG", "http://lanapavkov.com/content/exposures/exp29.JPG", "http://lanapavkov.com/content/exposures/exp30.JPG"],
"slikaKlasa": "exposures"

]


in my app.js I loop through this array to get four images on the screen that are actually buttons to trigger a gallery component



 <div className="photography_c">
this.state.fotografije.map((photography, index) =>
return <Gallery
naslov=photography.naslov
naslovnaSlika=photography.naslovnaSlika
naslovKlasa=photography.naslovKlasa
brSlika=photography.brSlika
key=photography.id
slikaKlasa=photography.slikaKlasa
openPhotography=() => this.injectPhotography(index) />
)
</div>


the actual gallery component looks like this



 const Gallery = (props) => 
return (
<div onClick=props.openPhotography className="singleGallery">
<div className=props.naslovKlasa>
<h3>props.naslov</h3>
<p>props.brSlika</p>
<img className="plus_icon" src="http://lanapavkov.com/content/more.png" alt="open" />
</div>
<img className=props.slikaKlasa src=props.naslovnaSlika alt="nova slika "/>
</div>
)



the openPhotography I use to import one of the clicked objects into an empty state and use its info to fill out another component that is the actual selected gallery. the function looks like this



 injectPhotography = (fotografijaIndex) => 
let brslikeuG = this.state;
brslikeuG = 1;
this.setState(brslikeuG: brslikeuG);

const updownPhotography = this.state;
updownPhotography.push("position-top-photography");
this.setState(updownPhotography: updownPhotography);
const selectedPhotography = this.state.fotografije.find((fotografija, index) => index === fotografijaIndex)
this.setState((prevState) => (
selectedPhotography
))



*brslikeuG is a number I print out on the page so the user knows how many images there are



the actual component with the sldes and images is this component



 const ContainerPhotography = (props) => 
return (
<div className=props.klasa.join(' ')>
<div className="arrow_holder">
<p className="br_slike">props.brSlike/props.selectedPhotography && props.selectedPhotography.slikeUGaleriji && props.selectedPhotography.slikeUGaleriji.length</p>
<img onClick=props.klikLevo src="http://lanapavkov.com/content/back_arrow.png" alt="right_arrow" />
<img onClick=props.klikDesno src="http://lanapavkov.com/content/back_arrow.png" alt="left_arrow" />
</div>
<div className="horizontal_container" style= left: props.left >
props.selectedPhotography && props.selectedPhotography.slikeUGaleriji && props.selectedPhotography.slikeUGaleriji.map((slika, index)=>
return <ImageLoopPhoto Key='Key-'+index url=slika />
)
</div>
<img onClick=props.zatvori src="http://lanapavkov.com/content/close.png" alt="close" className="close-popup" />
</div>
)



and it is called from the app.js



<ContainerPhotography
selectedPhotography=this.state.selectedPhotography
klasa=this.state.updownPhotography
zatvori=this.closePreviewPhotography
left=this.state.left
brSlike=this.state.brslikeuG
klikDesno=this.pomeranjeGalerijePhotoDesno
klikLevo=this.pomeranjeGalerijePhotoLevo/>


and the last component that prints images in a loop is this one



const ImageLoopPhoto = (props) => 
return (
<div className="horizontal_element">
<img src=props.url alt="alt"/>
</div>
)



when I close the actual slide component just the css classes are changed so I won't bother you with that.



THE PROBLEM: when you click on the first image, go through the gallery, close it and open the second gallery the images from the first gallery are still there and when you try to click the arrows the images change to the second array (sometimes they don't). I am not sure if this is a rerendering issue or just a bad practice of everything. I'm just starting out with react so please have patience and all advice is welcome



also you can see this live on lanapavkov.com if you go to photography on top and click around you can see the issue.










share|improve this question
























  • How ContainerPhotography component is being used and inside which component? Can you please share some code to demonstrate that?

    – imk
    Mar 21 at 20:47












  • @imk I have added it, it is called in app.js

    – srdjan_susa
    Mar 21 at 20:50







  • 1





    try adding the prop key=this.state.selectedPhotography.id to ContainerPhotography. That will reload the ContainerPhotography component when the selected photography changes. That may be what you want. If you could put this in a code sandbox or stack snippet, it would help debugging this...

    – Garrett Motzner
    Mar 21 at 23:16
















0















I am working on a custom react project and I have a problem that a wrong array of images is showing when a component should be rerendered, I am not sure what the real issue is but I think I might be missing a rerendering somewhere, i will try to explain as best as i can below please seek more info if you need it, also try to bear with me there's a link at the end :)



NOTE: gallery component is where you choose the gallery and ContainerPhotography is the one where image arrays that don't work are shown



this is the JSON object that i am using in state



 fotografije: [

"naslov": "Sculptures",
"id": "f00",
"brSlika": "10 image Gallery",
"naslovnaSlika": "http://lanapavkov.com/content/img1.png",
"naslovKlasa": "sculptures_naslov",
"slikeUGaleriji": ["http://lanapavkov.com/content/skulpture/skp0.jpg", "http://lanapavkov.com/content/skulpture/skp1.jpg", "http://lanapavkov.com/content/skulpture/skp2.jpg", "http://lanapavkov.com/content/skulpture/skp3.jpg", "http://lanapavkov.com/content/skulpture/skp4.jpg", "http://lanapavkov.com/content/skulpture/skp5.jpg", "http://lanapavkov.com/content/skulpture/skp6.jpg", "http://lanapavkov.com/content/skulpture/skp7.jpg", "http://lanapavkov.com/content/skulpture/skp8.jpg", "http://lanapavkov.com/content/skulpture/skp9.jpg"],
"slikaKlasa": "sculptures"
,
"naslov": "Captions",
"id": "f01",
"brSlika": "16 image Gallery",
"naslovnaSlika": "http://lanapavkov.com/content/una_gallery.png",
"naslovKlasa": "captions_naslov",
"slikeUGaleriji": ["http://lanapavkov.com/content/captions/cpt1.jpg", "http://lanapavkov.com/content/captions/cpt2.jpg","http://lanapavkov.com/content/captions/cpt3.jpg", "http://lanapavkov.com/content/captions/cpt4.jpg", "http://lanapavkov.com/content/captions/cpt5.jpg", "http://lanapavkov.com/content/captions/cpt6.jpg", "http://lanapavkov.com/content/captions/cpt7.jpg", "http://lanapavkov.com/content/captions/cpt8.jpg", "http://lanapavkov.com/content/captions/cpt9.jpg", "http://lanapavkov.com/content/captions/cpt10.jpg", "http://lanapavkov.com/content/captions/cpt11.jpg", "http://lanapavkov.com/content/captions/cpt12.jpg", "http://lanapavkov.com/content/captions/cpt13.jpg", "http://lanapavkov.com/content/captions/cpt14.jpg", "http://lanapavkov.com/content/captions/cpt15.jpg", "http://lanapavkov.com/content/captions/cpt16.jpg",],
"slikaKlasa": "captions"
,
"naslov": "Eva",
"id": "f02",
"brSlika": "9 image Gallery",
"naslovnaSlika": "http://lanapavkov.com/content/Eva_prez.png",
"naslovKlasa": "eva_naslov",
"slikeUGaleriji": ["http://lanapavkov.com/content/eva/1.jpg", "http://lanapavkov.com/content/eva/2.jpg", "http://lanapavkov.com/content/eva/3.jpg", "http://lanapavkov.com/content/eva/4.jpg", "http://lanapavkov.com/content/eva/4(1).jpg", "http://lanapavkov.com/content/eva/5.jpg", "http://lanapavkov.com/content/eva/6.jpg", "http://lanapavkov.com/content/eva/7.jpg", "http://lanapavkov.com/content/eva/8.jpg", "http://lanapavkov.com/content/eva/10.jpg", "http://lanapavkov.com/content/eva/11.jpg", "http://lanapavkov.com/content/eva/12.jpg", "http://lanapavkov.com/content/eva/13.jpg", "http://lanapavkov.com/content/eva/14.jpg", "http://lanapavkov.com/content/eva/15.jpg", "http://lanapavkov.com/content/eva/16.jpg", "http://lanapavkov.com/content/eva/17.jpg", "http://lanapavkov.com/content/eva/18.jpg", "http://lanapavkov.com/content/eva/19.jpg", "http://lanapavkov.com/content/eva/20.jpg", "http://lanapavkov.com/content/eva/21.jpg", "http://lanapavkov.com/content/eva/22.jpg", "http://lanapavkov.com/content/eva/23.jpg", "http://lanapavkov.com/content/eva/24.jpg"],
"slikaKlasa": "eva"
,
"naslov": "Exposures",
"id": "f03",
"brSlika": "19 image Gallery",
"naslovnaSlika": "http://lanapavkov.com/content/street_gallery_1.png",
"naslovKlasa": "exposures_naslov",
"slikeUGaleriji": ["http://lanapavkov.com/content/exposures/exp1.JPG", "http://lanapavkov.com/content/exposures/exp2.JPG", "http://lanapavkov.com/content/exposures/exp3.JPG", "http://lanapavkov.com/content/exposures/exp4.JPG", "http://lanapavkov.com/content/exposures/exp5.JPG", "http://lanapavkov.com/content/exposures/exp6.JPG", "http://lanapavkov.com/content/exposures/exp7.JPG", "http://lanapavkov.com/content/exposures/exp8.JPG", "http://lanapavkov.com/content/exposures/exp9.JPG", "http://lanapavkov.com/content/exposures/exp10.JPG", "http://lanapavkov.com/content/exposures/exp11.JPG", "http://lanapavkov.com/content/exposures/exp12.JPG", "http://lanapavkov.com/content/exposures/exp13.JPG", "http://lanapavkov.com/content/exposures/exp14.JPG", "http://lanapavkov.com/content/exposures/exp15.JPG", "http://lanapavkov.com/content/exposures/exp16.JPG", "http://lanapavkov.com/content/exposures/exp17.JPG", "http://lanapavkov.com/content/exposures/exp18.JPG", "http://lanapavkov.com/content/exposures/exp19.JPG", "http://lanapavkov.com/content/exposures/exp20.JPG", "http://lanapavkov.com/content/exposures/exp21.JPG", "http://lanapavkov.com/content/exposures/exp22.JPG", "http://lanapavkov.com/content/exposures/exp23.JPG", "http://lanapavkov.com/content/exposures/exp24.JPG", "http://lanapavkov.com/content/exposures/exp25.JPG", "http://lanapavkov.com/content/exposures/exp26.JPG", "http://lanapavkov.com/content/exposures/exp27.JPG", "http://lanapavkov.com/content/exposures/exp28.JPG", "http://lanapavkov.com/content/exposures/exp29.JPG", "http://lanapavkov.com/content/exposures/exp30.JPG"],
"slikaKlasa": "exposures"

]


in my app.js I loop through this array to get four images on the screen that are actually buttons to trigger a gallery component



 <div className="photography_c">
this.state.fotografije.map((photography, index) =>
return <Gallery
naslov=photography.naslov
naslovnaSlika=photography.naslovnaSlika
naslovKlasa=photography.naslovKlasa
brSlika=photography.brSlika
key=photography.id
slikaKlasa=photography.slikaKlasa
openPhotography=() => this.injectPhotography(index) />
)
</div>


the actual gallery component looks like this



 const Gallery = (props) => 
return (
<div onClick=props.openPhotography className="singleGallery">
<div className=props.naslovKlasa>
<h3>props.naslov</h3>
<p>props.brSlika</p>
<img className="plus_icon" src="http://lanapavkov.com/content/more.png" alt="open" />
</div>
<img className=props.slikaKlasa src=props.naslovnaSlika alt="nova slika "/>
</div>
)



the openPhotography I use to import one of the clicked objects into an empty state and use its info to fill out another component that is the actual selected gallery. the function looks like this



 injectPhotography = (fotografijaIndex) => 
let brslikeuG = this.state;
brslikeuG = 1;
this.setState(brslikeuG: brslikeuG);

const updownPhotography = this.state;
updownPhotography.push("position-top-photography");
this.setState(updownPhotography: updownPhotography);
const selectedPhotography = this.state.fotografije.find((fotografija, index) => index === fotografijaIndex)
this.setState((prevState) => (
selectedPhotography
))



*brslikeuG is a number I print out on the page so the user knows how many images there are



the actual component with the sldes and images is this component



 const ContainerPhotography = (props) => 
return (
<div className=props.klasa.join(' ')>
<div className="arrow_holder">
<p className="br_slike">props.brSlike/props.selectedPhotography && props.selectedPhotography.slikeUGaleriji && props.selectedPhotography.slikeUGaleriji.length</p>
<img onClick=props.klikLevo src="http://lanapavkov.com/content/back_arrow.png" alt="right_arrow" />
<img onClick=props.klikDesno src="http://lanapavkov.com/content/back_arrow.png" alt="left_arrow" />
</div>
<div className="horizontal_container" style= left: props.left >
props.selectedPhotography && props.selectedPhotography.slikeUGaleriji && props.selectedPhotography.slikeUGaleriji.map((slika, index)=>
return <ImageLoopPhoto Key='Key-'+index url=slika />
)
</div>
<img onClick=props.zatvori src="http://lanapavkov.com/content/close.png" alt="close" className="close-popup" />
</div>
)



and it is called from the app.js



<ContainerPhotography
selectedPhotography=this.state.selectedPhotography
klasa=this.state.updownPhotography
zatvori=this.closePreviewPhotography
left=this.state.left
brSlike=this.state.brslikeuG
klikDesno=this.pomeranjeGalerijePhotoDesno
klikLevo=this.pomeranjeGalerijePhotoLevo/>


and the last component that prints images in a loop is this one



const ImageLoopPhoto = (props) => 
return (
<div className="horizontal_element">
<img src=props.url alt="alt"/>
</div>
)



when I close the actual slide component just the css classes are changed so I won't bother you with that.



THE PROBLEM: when you click on the first image, go through the gallery, close it and open the second gallery the images from the first gallery are still there and when you try to click the arrows the images change to the second array (sometimes they don't). I am not sure if this is a rerendering issue or just a bad practice of everything. I'm just starting out with react so please have patience and all advice is welcome



also you can see this live on lanapavkov.com if you go to photography on top and click around you can see the issue.










share|improve this question
























  • How ContainerPhotography component is being used and inside which component? Can you please share some code to demonstrate that?

    – imk
    Mar 21 at 20:47












  • @imk I have added it, it is called in app.js

    – srdjan_susa
    Mar 21 at 20:50







  • 1





    try adding the prop key=this.state.selectedPhotography.id to ContainerPhotography. That will reload the ContainerPhotography component when the selected photography changes. That may be what you want. If you could put this in a code sandbox or stack snippet, it would help debugging this...

    – Garrett Motzner
    Mar 21 at 23:16














0












0








0








I am working on a custom react project and I have a problem that a wrong array of images is showing when a component should be rerendered, I am not sure what the real issue is but I think I might be missing a rerendering somewhere, i will try to explain as best as i can below please seek more info if you need it, also try to bear with me there's a link at the end :)



NOTE: gallery component is where you choose the gallery and ContainerPhotography is the one where image arrays that don't work are shown



this is the JSON object that i am using in state



 fotografije: [

"naslov": "Sculptures",
"id": "f00",
"brSlika": "10 image Gallery",
"naslovnaSlika": "http://lanapavkov.com/content/img1.png",
"naslovKlasa": "sculptures_naslov",
"slikeUGaleriji": ["http://lanapavkov.com/content/skulpture/skp0.jpg", "http://lanapavkov.com/content/skulpture/skp1.jpg", "http://lanapavkov.com/content/skulpture/skp2.jpg", "http://lanapavkov.com/content/skulpture/skp3.jpg", "http://lanapavkov.com/content/skulpture/skp4.jpg", "http://lanapavkov.com/content/skulpture/skp5.jpg", "http://lanapavkov.com/content/skulpture/skp6.jpg", "http://lanapavkov.com/content/skulpture/skp7.jpg", "http://lanapavkov.com/content/skulpture/skp8.jpg", "http://lanapavkov.com/content/skulpture/skp9.jpg"],
"slikaKlasa": "sculptures"
,
"naslov": "Captions",
"id": "f01",
"brSlika": "16 image Gallery",
"naslovnaSlika": "http://lanapavkov.com/content/una_gallery.png",
"naslovKlasa": "captions_naslov",
"slikeUGaleriji": ["http://lanapavkov.com/content/captions/cpt1.jpg", "http://lanapavkov.com/content/captions/cpt2.jpg","http://lanapavkov.com/content/captions/cpt3.jpg", "http://lanapavkov.com/content/captions/cpt4.jpg", "http://lanapavkov.com/content/captions/cpt5.jpg", "http://lanapavkov.com/content/captions/cpt6.jpg", "http://lanapavkov.com/content/captions/cpt7.jpg", "http://lanapavkov.com/content/captions/cpt8.jpg", "http://lanapavkov.com/content/captions/cpt9.jpg", "http://lanapavkov.com/content/captions/cpt10.jpg", "http://lanapavkov.com/content/captions/cpt11.jpg", "http://lanapavkov.com/content/captions/cpt12.jpg", "http://lanapavkov.com/content/captions/cpt13.jpg", "http://lanapavkov.com/content/captions/cpt14.jpg", "http://lanapavkov.com/content/captions/cpt15.jpg", "http://lanapavkov.com/content/captions/cpt16.jpg",],
"slikaKlasa": "captions"
,
"naslov": "Eva",
"id": "f02",
"brSlika": "9 image Gallery",
"naslovnaSlika": "http://lanapavkov.com/content/Eva_prez.png",
"naslovKlasa": "eva_naslov",
"slikeUGaleriji": ["http://lanapavkov.com/content/eva/1.jpg", "http://lanapavkov.com/content/eva/2.jpg", "http://lanapavkov.com/content/eva/3.jpg", "http://lanapavkov.com/content/eva/4.jpg", "http://lanapavkov.com/content/eva/4(1).jpg", "http://lanapavkov.com/content/eva/5.jpg", "http://lanapavkov.com/content/eva/6.jpg", "http://lanapavkov.com/content/eva/7.jpg", "http://lanapavkov.com/content/eva/8.jpg", "http://lanapavkov.com/content/eva/10.jpg", "http://lanapavkov.com/content/eva/11.jpg", "http://lanapavkov.com/content/eva/12.jpg", "http://lanapavkov.com/content/eva/13.jpg", "http://lanapavkov.com/content/eva/14.jpg", "http://lanapavkov.com/content/eva/15.jpg", "http://lanapavkov.com/content/eva/16.jpg", "http://lanapavkov.com/content/eva/17.jpg", "http://lanapavkov.com/content/eva/18.jpg", "http://lanapavkov.com/content/eva/19.jpg", "http://lanapavkov.com/content/eva/20.jpg", "http://lanapavkov.com/content/eva/21.jpg", "http://lanapavkov.com/content/eva/22.jpg", "http://lanapavkov.com/content/eva/23.jpg", "http://lanapavkov.com/content/eva/24.jpg"],
"slikaKlasa": "eva"
,
"naslov": "Exposures",
"id": "f03",
"brSlika": "19 image Gallery",
"naslovnaSlika": "http://lanapavkov.com/content/street_gallery_1.png",
"naslovKlasa": "exposures_naslov",
"slikeUGaleriji": ["http://lanapavkov.com/content/exposures/exp1.JPG", "http://lanapavkov.com/content/exposures/exp2.JPG", "http://lanapavkov.com/content/exposures/exp3.JPG", "http://lanapavkov.com/content/exposures/exp4.JPG", "http://lanapavkov.com/content/exposures/exp5.JPG", "http://lanapavkov.com/content/exposures/exp6.JPG", "http://lanapavkov.com/content/exposures/exp7.JPG", "http://lanapavkov.com/content/exposures/exp8.JPG", "http://lanapavkov.com/content/exposures/exp9.JPG", "http://lanapavkov.com/content/exposures/exp10.JPG", "http://lanapavkov.com/content/exposures/exp11.JPG", "http://lanapavkov.com/content/exposures/exp12.JPG", "http://lanapavkov.com/content/exposures/exp13.JPG", "http://lanapavkov.com/content/exposures/exp14.JPG", "http://lanapavkov.com/content/exposures/exp15.JPG", "http://lanapavkov.com/content/exposures/exp16.JPG", "http://lanapavkov.com/content/exposures/exp17.JPG", "http://lanapavkov.com/content/exposures/exp18.JPG", "http://lanapavkov.com/content/exposures/exp19.JPG", "http://lanapavkov.com/content/exposures/exp20.JPG", "http://lanapavkov.com/content/exposures/exp21.JPG", "http://lanapavkov.com/content/exposures/exp22.JPG", "http://lanapavkov.com/content/exposures/exp23.JPG", "http://lanapavkov.com/content/exposures/exp24.JPG", "http://lanapavkov.com/content/exposures/exp25.JPG", "http://lanapavkov.com/content/exposures/exp26.JPG", "http://lanapavkov.com/content/exposures/exp27.JPG", "http://lanapavkov.com/content/exposures/exp28.JPG", "http://lanapavkov.com/content/exposures/exp29.JPG", "http://lanapavkov.com/content/exposures/exp30.JPG"],
"slikaKlasa": "exposures"

]


in my app.js I loop through this array to get four images on the screen that are actually buttons to trigger a gallery component



 <div className="photography_c">
this.state.fotografije.map((photography, index) =>
return <Gallery
naslov=photography.naslov
naslovnaSlika=photography.naslovnaSlika
naslovKlasa=photography.naslovKlasa
brSlika=photography.brSlika
key=photography.id
slikaKlasa=photography.slikaKlasa
openPhotography=() => this.injectPhotography(index) />
)
</div>


the actual gallery component looks like this



 const Gallery = (props) => 
return (
<div onClick=props.openPhotography className="singleGallery">
<div className=props.naslovKlasa>
<h3>props.naslov</h3>
<p>props.brSlika</p>
<img className="plus_icon" src="http://lanapavkov.com/content/more.png" alt="open" />
</div>
<img className=props.slikaKlasa src=props.naslovnaSlika alt="nova slika "/>
</div>
)



the openPhotography I use to import one of the clicked objects into an empty state and use its info to fill out another component that is the actual selected gallery. the function looks like this



 injectPhotography = (fotografijaIndex) => 
let brslikeuG = this.state;
brslikeuG = 1;
this.setState(brslikeuG: brslikeuG);

const updownPhotography = this.state;
updownPhotography.push("position-top-photography");
this.setState(updownPhotography: updownPhotography);
const selectedPhotography = this.state.fotografije.find((fotografija, index) => index === fotografijaIndex)
this.setState((prevState) => (
selectedPhotography
))



*brslikeuG is a number I print out on the page so the user knows how many images there are



the actual component with the sldes and images is this component



 const ContainerPhotography = (props) => 
return (
<div className=props.klasa.join(' ')>
<div className="arrow_holder">
<p className="br_slike">props.brSlike/props.selectedPhotography && props.selectedPhotography.slikeUGaleriji && props.selectedPhotography.slikeUGaleriji.length</p>
<img onClick=props.klikLevo src="http://lanapavkov.com/content/back_arrow.png" alt="right_arrow" />
<img onClick=props.klikDesno src="http://lanapavkov.com/content/back_arrow.png" alt="left_arrow" />
</div>
<div className="horizontal_container" style= left: props.left >
props.selectedPhotography && props.selectedPhotography.slikeUGaleriji && props.selectedPhotography.slikeUGaleriji.map((slika, index)=>
return <ImageLoopPhoto Key='Key-'+index url=slika />
)
</div>
<img onClick=props.zatvori src="http://lanapavkov.com/content/close.png" alt="close" className="close-popup" />
</div>
)



and it is called from the app.js



<ContainerPhotography
selectedPhotography=this.state.selectedPhotography
klasa=this.state.updownPhotography
zatvori=this.closePreviewPhotography
left=this.state.left
brSlike=this.state.brslikeuG
klikDesno=this.pomeranjeGalerijePhotoDesno
klikLevo=this.pomeranjeGalerijePhotoLevo/>


and the last component that prints images in a loop is this one



const ImageLoopPhoto = (props) => 
return (
<div className="horizontal_element">
<img src=props.url alt="alt"/>
</div>
)



when I close the actual slide component just the css classes are changed so I won't bother you with that.



THE PROBLEM: when you click on the first image, go through the gallery, close it and open the second gallery the images from the first gallery are still there and when you try to click the arrows the images change to the second array (sometimes they don't). I am not sure if this is a rerendering issue or just a bad practice of everything. I'm just starting out with react so please have patience and all advice is welcome



also you can see this live on lanapavkov.com if you go to photography on top and click around you can see the issue.










share|improve this question
















I am working on a custom react project and I have a problem that a wrong array of images is showing when a component should be rerendered, I am not sure what the real issue is but I think I might be missing a rerendering somewhere, i will try to explain as best as i can below please seek more info if you need it, also try to bear with me there's a link at the end :)



NOTE: gallery component is where you choose the gallery and ContainerPhotography is the one where image arrays that don't work are shown



this is the JSON object that i am using in state



 fotografije: [

"naslov": "Sculptures",
"id": "f00",
"brSlika": "10 image Gallery",
"naslovnaSlika": "http://lanapavkov.com/content/img1.png",
"naslovKlasa": "sculptures_naslov",
"slikeUGaleriji": ["http://lanapavkov.com/content/skulpture/skp0.jpg", "http://lanapavkov.com/content/skulpture/skp1.jpg", "http://lanapavkov.com/content/skulpture/skp2.jpg", "http://lanapavkov.com/content/skulpture/skp3.jpg", "http://lanapavkov.com/content/skulpture/skp4.jpg", "http://lanapavkov.com/content/skulpture/skp5.jpg", "http://lanapavkov.com/content/skulpture/skp6.jpg", "http://lanapavkov.com/content/skulpture/skp7.jpg", "http://lanapavkov.com/content/skulpture/skp8.jpg", "http://lanapavkov.com/content/skulpture/skp9.jpg"],
"slikaKlasa": "sculptures"
,
"naslov": "Captions",
"id": "f01",
"brSlika": "16 image Gallery",
"naslovnaSlika": "http://lanapavkov.com/content/una_gallery.png",
"naslovKlasa": "captions_naslov",
"slikeUGaleriji": ["http://lanapavkov.com/content/captions/cpt1.jpg", "http://lanapavkov.com/content/captions/cpt2.jpg","http://lanapavkov.com/content/captions/cpt3.jpg", "http://lanapavkov.com/content/captions/cpt4.jpg", "http://lanapavkov.com/content/captions/cpt5.jpg", "http://lanapavkov.com/content/captions/cpt6.jpg", "http://lanapavkov.com/content/captions/cpt7.jpg", "http://lanapavkov.com/content/captions/cpt8.jpg", "http://lanapavkov.com/content/captions/cpt9.jpg", "http://lanapavkov.com/content/captions/cpt10.jpg", "http://lanapavkov.com/content/captions/cpt11.jpg", "http://lanapavkov.com/content/captions/cpt12.jpg", "http://lanapavkov.com/content/captions/cpt13.jpg", "http://lanapavkov.com/content/captions/cpt14.jpg", "http://lanapavkov.com/content/captions/cpt15.jpg", "http://lanapavkov.com/content/captions/cpt16.jpg",],
"slikaKlasa": "captions"
,
"naslov": "Eva",
"id": "f02",
"brSlika": "9 image Gallery",
"naslovnaSlika": "http://lanapavkov.com/content/Eva_prez.png",
"naslovKlasa": "eva_naslov",
"slikeUGaleriji": ["http://lanapavkov.com/content/eva/1.jpg", "http://lanapavkov.com/content/eva/2.jpg", "http://lanapavkov.com/content/eva/3.jpg", "http://lanapavkov.com/content/eva/4.jpg", "http://lanapavkov.com/content/eva/4(1).jpg", "http://lanapavkov.com/content/eva/5.jpg", "http://lanapavkov.com/content/eva/6.jpg", "http://lanapavkov.com/content/eva/7.jpg", "http://lanapavkov.com/content/eva/8.jpg", "http://lanapavkov.com/content/eva/10.jpg", "http://lanapavkov.com/content/eva/11.jpg", "http://lanapavkov.com/content/eva/12.jpg", "http://lanapavkov.com/content/eva/13.jpg", "http://lanapavkov.com/content/eva/14.jpg", "http://lanapavkov.com/content/eva/15.jpg", "http://lanapavkov.com/content/eva/16.jpg", "http://lanapavkov.com/content/eva/17.jpg", "http://lanapavkov.com/content/eva/18.jpg", "http://lanapavkov.com/content/eva/19.jpg", "http://lanapavkov.com/content/eva/20.jpg", "http://lanapavkov.com/content/eva/21.jpg", "http://lanapavkov.com/content/eva/22.jpg", "http://lanapavkov.com/content/eva/23.jpg", "http://lanapavkov.com/content/eva/24.jpg"],
"slikaKlasa": "eva"
,
"naslov": "Exposures",
"id": "f03",
"brSlika": "19 image Gallery",
"naslovnaSlika": "http://lanapavkov.com/content/street_gallery_1.png",
"naslovKlasa": "exposures_naslov",
"slikeUGaleriji": ["http://lanapavkov.com/content/exposures/exp1.JPG", "http://lanapavkov.com/content/exposures/exp2.JPG", "http://lanapavkov.com/content/exposures/exp3.JPG", "http://lanapavkov.com/content/exposures/exp4.JPG", "http://lanapavkov.com/content/exposures/exp5.JPG", "http://lanapavkov.com/content/exposures/exp6.JPG", "http://lanapavkov.com/content/exposures/exp7.JPG", "http://lanapavkov.com/content/exposures/exp8.JPG", "http://lanapavkov.com/content/exposures/exp9.JPG", "http://lanapavkov.com/content/exposures/exp10.JPG", "http://lanapavkov.com/content/exposures/exp11.JPG", "http://lanapavkov.com/content/exposures/exp12.JPG", "http://lanapavkov.com/content/exposures/exp13.JPG", "http://lanapavkov.com/content/exposures/exp14.JPG", "http://lanapavkov.com/content/exposures/exp15.JPG", "http://lanapavkov.com/content/exposures/exp16.JPG", "http://lanapavkov.com/content/exposures/exp17.JPG", "http://lanapavkov.com/content/exposures/exp18.JPG", "http://lanapavkov.com/content/exposures/exp19.JPG", "http://lanapavkov.com/content/exposures/exp20.JPG", "http://lanapavkov.com/content/exposures/exp21.JPG", "http://lanapavkov.com/content/exposures/exp22.JPG", "http://lanapavkov.com/content/exposures/exp23.JPG", "http://lanapavkov.com/content/exposures/exp24.JPG", "http://lanapavkov.com/content/exposures/exp25.JPG", "http://lanapavkov.com/content/exposures/exp26.JPG", "http://lanapavkov.com/content/exposures/exp27.JPG", "http://lanapavkov.com/content/exposures/exp28.JPG", "http://lanapavkov.com/content/exposures/exp29.JPG", "http://lanapavkov.com/content/exposures/exp30.JPG"],
"slikaKlasa": "exposures"

]


in my app.js I loop through this array to get four images on the screen that are actually buttons to trigger a gallery component



 <div className="photography_c">
this.state.fotografije.map((photography, index) =>
return <Gallery
naslov=photography.naslov
naslovnaSlika=photography.naslovnaSlika
naslovKlasa=photography.naslovKlasa
brSlika=photography.brSlika
key=photography.id
slikaKlasa=photography.slikaKlasa
openPhotography=() => this.injectPhotography(index) />
)
</div>


the actual gallery component looks like this



 const Gallery = (props) => 
return (
<div onClick=props.openPhotography className="singleGallery">
<div className=props.naslovKlasa>
<h3>props.naslov</h3>
<p>props.brSlika</p>
<img className="plus_icon" src="http://lanapavkov.com/content/more.png" alt="open" />
</div>
<img className=props.slikaKlasa src=props.naslovnaSlika alt="nova slika "/>
</div>
)



the openPhotography I use to import one of the clicked objects into an empty state and use its info to fill out another component that is the actual selected gallery. the function looks like this



 injectPhotography = (fotografijaIndex) => 
let brslikeuG = this.state;
brslikeuG = 1;
this.setState(brslikeuG: brslikeuG);

const updownPhotography = this.state;
updownPhotography.push("position-top-photography");
this.setState(updownPhotography: updownPhotography);
const selectedPhotography = this.state.fotografije.find((fotografija, index) => index === fotografijaIndex)
this.setState((prevState) => (
selectedPhotography
))



*brslikeuG is a number I print out on the page so the user knows how many images there are



the actual component with the sldes and images is this component



 const ContainerPhotography = (props) => 
return (
<div className=props.klasa.join(' ')>
<div className="arrow_holder">
<p className="br_slike">props.brSlike/props.selectedPhotography && props.selectedPhotography.slikeUGaleriji && props.selectedPhotography.slikeUGaleriji.length</p>
<img onClick=props.klikLevo src="http://lanapavkov.com/content/back_arrow.png" alt="right_arrow" />
<img onClick=props.klikDesno src="http://lanapavkov.com/content/back_arrow.png" alt="left_arrow" />
</div>
<div className="horizontal_container" style= left: props.left >
props.selectedPhotography && props.selectedPhotography.slikeUGaleriji && props.selectedPhotography.slikeUGaleriji.map((slika, index)=>
return <ImageLoopPhoto Key='Key-'+index url=slika />
)
</div>
<img onClick=props.zatvori src="http://lanapavkov.com/content/close.png" alt="close" className="close-popup" />
</div>
)



and it is called from the app.js



<ContainerPhotography
selectedPhotography=this.state.selectedPhotography
klasa=this.state.updownPhotography
zatvori=this.closePreviewPhotography
left=this.state.left
brSlike=this.state.brslikeuG
klikDesno=this.pomeranjeGalerijePhotoDesno
klikLevo=this.pomeranjeGalerijePhotoLevo/>


and the last component that prints images in a loop is this one



const ImageLoopPhoto = (props) => 
return (
<div className="horizontal_element">
<img src=props.url alt="alt"/>
</div>
)



when I close the actual slide component just the css classes are changed so I won't bother you with that.



THE PROBLEM: when you click on the first image, go through the gallery, close it and open the second gallery the images from the first gallery are still there and when you try to click the arrows the images change to the second array (sometimes they don't). I am not sure if this is a rerendering issue or just a bad practice of everything. I'm just starting out with react so please have patience and all advice is welcome



also you can see this live on lanapavkov.com if you go to photography on top and click around you can see the issue.







reactjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 21 at 20:49







srdjan_susa

















asked Mar 21 at 19:59









srdjan_susasrdjan_susa

409




409












  • How ContainerPhotography component is being used and inside which component? Can you please share some code to demonstrate that?

    – imk
    Mar 21 at 20:47












  • @imk I have added it, it is called in app.js

    – srdjan_susa
    Mar 21 at 20:50







  • 1





    try adding the prop key=this.state.selectedPhotography.id to ContainerPhotography. That will reload the ContainerPhotography component when the selected photography changes. That may be what you want. If you could put this in a code sandbox or stack snippet, it would help debugging this...

    – Garrett Motzner
    Mar 21 at 23:16


















  • How ContainerPhotography component is being used and inside which component? Can you please share some code to demonstrate that?

    – imk
    Mar 21 at 20:47












  • @imk I have added it, it is called in app.js

    – srdjan_susa
    Mar 21 at 20:50







  • 1





    try adding the prop key=this.state.selectedPhotography.id to ContainerPhotography. That will reload the ContainerPhotography component when the selected photography changes. That may be what you want. If you could put this in a code sandbox or stack snippet, it would help debugging this...

    – Garrett Motzner
    Mar 21 at 23:16

















How ContainerPhotography component is being used and inside which component? Can you please share some code to demonstrate that?

– imk
Mar 21 at 20:47






How ContainerPhotography component is being used and inside which component? Can you please share some code to demonstrate that?

– imk
Mar 21 at 20:47














@imk I have added it, it is called in app.js

– srdjan_susa
Mar 21 at 20:50






@imk I have added it, it is called in app.js

– srdjan_susa
Mar 21 at 20:50





1




1





try adding the prop key=this.state.selectedPhotography.id to ContainerPhotography. That will reload the ContainerPhotography component when the selected photography changes. That may be what you want. If you could put this in a code sandbox or stack snippet, it would help debugging this...

– Garrett Motzner
Mar 21 at 23:16






try adding the prop key=this.state.selectedPhotography.id to ContainerPhotography. That will reload the ContainerPhotography component when the selected photography changes. That may be what you want. If you could put this in a code sandbox or stack snippet, it would help debugging this...

– Garrett Motzner
Mar 21 at 23:16













1 Answer
1






active

oldest

votes


















0














Can you please replace component ContainerPhotography with below codes. notice that i changed the props Key to key. lowercase k. and use url as key.



 const ContainerPhotography = (props) => 
return (
<div className=props.klasa.join(' ')>
<div className="arrow_holder">
<p className="br_slike">props.brSlike/props.selectedPhotography && props.selectedPhotography.slikeUGaleriji && props.selectedPhotography.slikeUGaleriji.length</p>
<img onClick=props.klikLevo src="http://lanapavkov.com/content/back_arrow.png" alt="right_arrow" />
<img onClick=props.klikDesno src="http://lanapavkov.com/content/back_arrow.png" alt="left_arrow" />
</div>
<div className="horizontal_container" style= left: props.left >
props.selectedPhotography && props.selectedPhotography.slikeUGaleriji && props.selectedPhotography.slikeUGaleriji.map((slika, index)=>
return <ImageLoopPhoto key=slika url=slika />
)
</div>
<img onClick=props.zatvori src="http://lanapavkov.com/content/close.png" alt="close" className="close-popup" />
</div>
)



let me know, if this fix your issues.
Thanks






share|improve this answer




















  • 1





    Shouldn't you change the key prop in the component doing the iteration, instead of in the item component?

    – Garrett Motzner
    Mar 21 at 21:25











  • just found that i posted the wrong version of my answer. thanks Motzner !!!

    – imk
    Mar 21 at 21:49











  • um, I don't think that's correct yet :) Your key is based solely on the index, and that means that things can get mixed up if items change order...

    – Garrett Motzner
    Mar 21 at 22:04






  • 1





    yeah, it's unique, but it doesn't always correlate to the same item. see Index as key is an anti-pattern. You can sometimes get away with it, but when things are not appearing in the order you expect, or things aren't updating, then it's usually because your key is an index, not an identifier.

    – Garrett Motzner
    Mar 21 at 22:47






  • 1





    You are right. But in this case , using index for key is OK, i guess. As the list is static, it has no id and, never be re-ordered. Thanks Motzner

    – imk
    Mar 21 at 23:05











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288398%2fsetstate-not-re-rendering-and-galleries-getting-mixed%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Can you please replace component ContainerPhotography with below codes. notice that i changed the props Key to key. lowercase k. and use url as key.



 const ContainerPhotography = (props) => 
return (
<div className=props.klasa.join(' ')>
<div className="arrow_holder">
<p className="br_slike">props.brSlike/props.selectedPhotography && props.selectedPhotography.slikeUGaleriji && props.selectedPhotography.slikeUGaleriji.length</p>
<img onClick=props.klikLevo src="http://lanapavkov.com/content/back_arrow.png" alt="right_arrow" />
<img onClick=props.klikDesno src="http://lanapavkov.com/content/back_arrow.png" alt="left_arrow" />
</div>
<div className="horizontal_container" style= left: props.left >
props.selectedPhotography && props.selectedPhotography.slikeUGaleriji && props.selectedPhotography.slikeUGaleriji.map((slika, index)=>
return <ImageLoopPhoto key=slika url=slika />
)
</div>
<img onClick=props.zatvori src="http://lanapavkov.com/content/close.png" alt="close" className="close-popup" />
</div>
)



let me know, if this fix your issues.
Thanks






share|improve this answer




















  • 1





    Shouldn't you change the key prop in the component doing the iteration, instead of in the item component?

    – Garrett Motzner
    Mar 21 at 21:25











  • just found that i posted the wrong version of my answer. thanks Motzner !!!

    – imk
    Mar 21 at 21:49











  • um, I don't think that's correct yet :) Your key is based solely on the index, and that means that things can get mixed up if items change order...

    – Garrett Motzner
    Mar 21 at 22:04






  • 1





    yeah, it's unique, but it doesn't always correlate to the same item. see Index as key is an anti-pattern. You can sometimes get away with it, but when things are not appearing in the order you expect, or things aren't updating, then it's usually because your key is an index, not an identifier.

    – Garrett Motzner
    Mar 21 at 22:47






  • 1





    You are right. But in this case , using index for key is OK, i guess. As the list is static, it has no id and, never be re-ordered. Thanks Motzner

    – imk
    Mar 21 at 23:05















0














Can you please replace component ContainerPhotography with below codes. notice that i changed the props Key to key. lowercase k. and use url as key.



 const ContainerPhotography = (props) => 
return (
<div className=props.klasa.join(' ')>
<div className="arrow_holder">
<p className="br_slike">props.brSlike/props.selectedPhotography && props.selectedPhotography.slikeUGaleriji && props.selectedPhotography.slikeUGaleriji.length</p>
<img onClick=props.klikLevo src="http://lanapavkov.com/content/back_arrow.png" alt="right_arrow" />
<img onClick=props.klikDesno src="http://lanapavkov.com/content/back_arrow.png" alt="left_arrow" />
</div>
<div className="horizontal_container" style= left: props.left >
props.selectedPhotography && props.selectedPhotography.slikeUGaleriji && props.selectedPhotography.slikeUGaleriji.map((slika, index)=>
return <ImageLoopPhoto key=slika url=slika />
)
</div>
<img onClick=props.zatvori src="http://lanapavkov.com/content/close.png" alt="close" className="close-popup" />
</div>
)



let me know, if this fix your issues.
Thanks






share|improve this answer




















  • 1





    Shouldn't you change the key prop in the component doing the iteration, instead of in the item component?

    – Garrett Motzner
    Mar 21 at 21:25











  • just found that i posted the wrong version of my answer. thanks Motzner !!!

    – imk
    Mar 21 at 21:49











  • um, I don't think that's correct yet :) Your key is based solely on the index, and that means that things can get mixed up if items change order...

    – Garrett Motzner
    Mar 21 at 22:04






  • 1





    yeah, it's unique, but it doesn't always correlate to the same item. see Index as key is an anti-pattern. You can sometimes get away with it, but when things are not appearing in the order you expect, or things aren't updating, then it's usually because your key is an index, not an identifier.

    – Garrett Motzner
    Mar 21 at 22:47






  • 1





    You are right. But in this case , using index for key is OK, i guess. As the list is static, it has no id and, never be re-ordered. Thanks Motzner

    – imk
    Mar 21 at 23:05













0












0








0







Can you please replace component ContainerPhotography with below codes. notice that i changed the props Key to key. lowercase k. and use url as key.



 const ContainerPhotography = (props) => 
return (
<div className=props.klasa.join(' ')>
<div className="arrow_holder">
<p className="br_slike">props.brSlike/props.selectedPhotography && props.selectedPhotography.slikeUGaleriji && props.selectedPhotography.slikeUGaleriji.length</p>
<img onClick=props.klikLevo src="http://lanapavkov.com/content/back_arrow.png" alt="right_arrow" />
<img onClick=props.klikDesno src="http://lanapavkov.com/content/back_arrow.png" alt="left_arrow" />
</div>
<div className="horizontal_container" style= left: props.left >
props.selectedPhotography && props.selectedPhotography.slikeUGaleriji && props.selectedPhotography.slikeUGaleriji.map((slika, index)=>
return <ImageLoopPhoto key=slika url=slika />
)
</div>
<img onClick=props.zatvori src="http://lanapavkov.com/content/close.png" alt="close" className="close-popup" />
</div>
)



let me know, if this fix your issues.
Thanks






share|improve this answer















Can you please replace component ContainerPhotography with below codes. notice that i changed the props Key to key. lowercase k. and use url as key.



 const ContainerPhotography = (props) => 
return (
<div className=props.klasa.join(' ')>
<div className="arrow_holder">
<p className="br_slike">props.brSlike/props.selectedPhotography && props.selectedPhotography.slikeUGaleriji && props.selectedPhotography.slikeUGaleriji.length</p>
<img onClick=props.klikLevo src="http://lanapavkov.com/content/back_arrow.png" alt="right_arrow" />
<img onClick=props.klikDesno src="http://lanapavkov.com/content/back_arrow.png" alt="left_arrow" />
</div>
<div className="horizontal_container" style= left: props.left >
props.selectedPhotography && props.selectedPhotography.slikeUGaleriji && props.selectedPhotography.slikeUGaleriji.map((slika, index)=>
return <ImageLoopPhoto key=slika url=slika />
)
</div>
<img onClick=props.zatvori src="http://lanapavkov.com/content/close.png" alt="close" className="close-popup" />
</div>
)



let me know, if this fix your issues.
Thanks







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 23 at 18:55

























answered Mar 21 at 21:19









imkimk

846




846







  • 1





    Shouldn't you change the key prop in the component doing the iteration, instead of in the item component?

    – Garrett Motzner
    Mar 21 at 21:25











  • just found that i posted the wrong version of my answer. thanks Motzner !!!

    – imk
    Mar 21 at 21:49











  • um, I don't think that's correct yet :) Your key is based solely on the index, and that means that things can get mixed up if items change order...

    – Garrett Motzner
    Mar 21 at 22:04






  • 1





    yeah, it's unique, but it doesn't always correlate to the same item. see Index as key is an anti-pattern. You can sometimes get away with it, but when things are not appearing in the order you expect, or things aren't updating, then it's usually because your key is an index, not an identifier.

    – Garrett Motzner
    Mar 21 at 22:47






  • 1





    You are right. But in this case , using index for key is OK, i guess. As the list is static, it has no id and, never be re-ordered. Thanks Motzner

    – imk
    Mar 21 at 23:05












  • 1





    Shouldn't you change the key prop in the component doing the iteration, instead of in the item component?

    – Garrett Motzner
    Mar 21 at 21:25











  • just found that i posted the wrong version of my answer. thanks Motzner !!!

    – imk
    Mar 21 at 21:49











  • um, I don't think that's correct yet :) Your key is based solely on the index, and that means that things can get mixed up if items change order...

    – Garrett Motzner
    Mar 21 at 22:04






  • 1





    yeah, it's unique, but it doesn't always correlate to the same item. see Index as key is an anti-pattern. You can sometimes get away with it, but when things are not appearing in the order you expect, or things aren't updating, then it's usually because your key is an index, not an identifier.

    – Garrett Motzner
    Mar 21 at 22:47






  • 1





    You are right. But in this case , using index for key is OK, i guess. As the list is static, it has no id and, never be re-ordered. Thanks Motzner

    – imk
    Mar 21 at 23:05







1




1





Shouldn't you change the key prop in the component doing the iteration, instead of in the item component?

– Garrett Motzner
Mar 21 at 21:25





Shouldn't you change the key prop in the component doing the iteration, instead of in the item component?

– Garrett Motzner
Mar 21 at 21:25













just found that i posted the wrong version of my answer. thanks Motzner !!!

– imk
Mar 21 at 21:49





just found that i posted the wrong version of my answer. thanks Motzner !!!

– imk
Mar 21 at 21:49













um, I don't think that's correct yet :) Your key is based solely on the index, and that means that things can get mixed up if items change order...

– Garrett Motzner
Mar 21 at 22:04





um, I don't think that's correct yet :) Your key is based solely on the index, and that means that things can get mixed up if items change order...

– Garrett Motzner
Mar 21 at 22:04




1




1





yeah, it's unique, but it doesn't always correlate to the same item. see Index as key is an anti-pattern. You can sometimes get away with it, but when things are not appearing in the order you expect, or things aren't updating, then it's usually because your key is an index, not an identifier.

– Garrett Motzner
Mar 21 at 22:47





yeah, it's unique, but it doesn't always correlate to the same item. see Index as key is an anti-pattern. You can sometimes get away with it, but when things are not appearing in the order you expect, or things aren't updating, then it's usually because your key is an index, not an identifier.

– Garrett Motzner
Mar 21 at 22:47




1




1





You are right. But in this case , using index for key is OK, i guess. As the list is static, it has no id and, never be re-ordered. Thanks Motzner

– imk
Mar 21 at 23:05





You are right. But in this case , using index for key is OK, i guess. As the list is static, it has no id and, never be re-ordered. Thanks Motzner

– imk
Mar 21 at 23:05



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288398%2fsetstate-not-re-rendering-and-galleries-getting-mixed%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript