Skip to content

Commit d89fef2

Browse files
authored
Refactor deprecated UNSAFE_componentWillReceiveProps (#52)
1 parent e1323ce commit d89fef2

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,17 @@ export default class Carousel extends Component {
123123
autobind(this);
124124
}
125125

126-
// eslint-disable-next-line
127-
UNSAFE_componentWillReceiveProps(newProps) {
128-
const { currentSlide } = this.state;
129-
const numChildren = Children.count(newProps.children);
126+
static getDerivedStateFromProps(props, state) {
127+
const { currentSlide } = state;
128+
const numChildren = Children.count(props.children);
130129

131130
if (currentSlide >= numChildren) {
132131
// The currentSlide index is no longer valid, so move to the last valid index
133-
this.setState({
132+
return {
134133
currentSlide: numChildren ? numChildren - 1 : 0
135-
});
134+
};
136135
}
136+
return null;
137137
}
138138

139139
componentDidUpdate(prevProps, prevState) {

0 commit comments

Comments
 (0)