Skip to content

Commit

Permalink
Handle useEffect with array value as dependency
Browse files Browse the repository at this point in the history
As it only checks object identity, when we pass in a new
array each time (even with the same values) it considers that
changed, but we only want it changes if the values _in_ the
array change. Achieved with `.join(' ')`ing the values.
  • Loading branch information
nicksellen committed May 22, 2020
1 parent 21be47d commit 3aa531c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion modules/core/client/components/Board.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import isArray from 'lodash/isArray';

import { selectPhoto } from '../services/photos.service';
import { $broadcast } from '@/modules/core/client/services/angular-compat';

Expand Down Expand Up @@ -50,7 +52,7 @@ export default function Board({
return () => {
$broadcast('photoCreditsRemoved', photoObject);
};
}, [names]);
}, [isArray(names) ? names.join(' ') : names]);

if (photo) {
style
Expand Down

0 comments on commit 3aa531c

Please sign in to comment.