Skip to content

Commit

Permalink
refactor: component should update if props or imgixParams change
Browse files Browse the repository at this point in the history
  • Loading branch information
ericdeansanchez committed Apr 22, 2021
1 parent 5275e25 commit 4dd1499
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/react-imgix-bg.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import constructUrl from "./constructUrl";
import extractQueryParams from "./extractQueryParams";
import findClosest from "./findClosest";
import targetWidths from "./targetWidths";
import { shallowEqual } from "./common";

const noop = () => {};

Expand Down Expand Up @@ -46,7 +47,17 @@ class BackgroundImpl extends React.Component {
return true;
}

return false;
// If we made it here, we need to check if the "top-level"
// props have changed (e.g. disableLibraryParam).
const shallowPropsEqual = shallowEqual(this.props, nextProps);

// We also need to check the imgixParams.
const shallowParamsEqual = shallowEqual(
this.props.imgixParams,
nextProps.imgixParams
);

return shallowPropsEqual && shallowParamsEqual;
}

render() {
Expand Down

0 comments on commit 4dd1499

Please sign in to comment.