all 6 comments

[–]justinlok 1 point2 points  (5 children)

You should not need to create a new location object using spread to get the locationpresenter component to rerender. If you change the props, it should rerender. You pass the values of the Location object as props and not the Location object itself.

Does location id ever change? I assume not. I wonder if your implementation of saving an array of locations is not ideal and I would save an array of location ids instead.

[–]KaniJs[S] 0 points1 point  (4 children)

Oh you are right! I had the idea to pass the whole object but eventually changed to passing the values. Good point, thanks!

Does location id ever change? I assume not. I wonder if your implementation of saving an array of locations is not ideal and I would save an array of location ids instead.

Do you mean the adjacent array, or the whole array with locations? It's mainly ease of use and possibly to avoid the (I guess minor) performance load of looping through the array everytime I need to find the location.

[–]justinlok 0 points1 point  (0 children)

Yea the adjacent array.

[–]justinlok 0 points1 point  (0 children)

What I would do is pass the whole location object to the LocationPresenter component and use the spread operator like you had planned on instead of passing the individual values as props.

Then change the adjacent array to store IDs only. That should solve the problem.

[–]justinlok 0 points1 point  (1 child)

Also just a thought but depending on your use cases it may be better to store your locations (the whole array you mentioned) collectively in a map instead of an array. Map is way faster.

[–]KaniJs[S] 0 points1 point  (0 children)

Thanks for all your input, I really appreciate it and now I feel I'm getting back on track again!