Skip to content

Commit c5c6a8b

Browse files
authored
feat: replace unsafe deprecated methods (jquense#2216)
This replaces deprecated React methods from the components, leading the way to eventual StrictMode compliance. jquense#1200 jquense#1777 jquense#1481 jquense#2126 jquense#2104 jquense#2105 jquense#1526
1 parent 1b7d8bf commit c5c6a8b

File tree

7 files changed

+25
-43
lines changed

7 files changed

+25
-43
lines changed

src/BackgroundCells.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class BackgroundCells extends React.Component {
2424
this._teardownSelectable()
2525
}
2626

27-
UNSAFE_componentWillReceiveProps(nextProps) {
28-
if (nextProps.selectable && !this.props.selectable) this._selectable()
27+
componentDidUpdate(prevProps) {
28+
if (!prevProps.selectable && this.props.selectable) this._selectable()
2929

30-
if (!nextProps.selectable && this.props.selectable)
30+
if (prevProps.selectable && !this.props.selectable)
3131
this._teardownSelectable()
3232
}
3333

src/Calendar.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -877,14 +877,14 @@ class Calendar extends React.Component {
877877
super(...args)
878878

879879
this.state = {
880-
context: this.getContext(this.props),
880+
context: Calendar.getContext(this.props),
881881
}
882882
}
883-
UNSAFE_componentWillReceiveProps(nextProps) {
884-
this.setState({ context: this.getContext(nextProps) })
883+
static getDerivedStateFromProps(nextProps) {
884+
return { context: Calendar.getContext(nextProps) }
885885
}
886886

887-
getContext({
887+
static getContext({
888888
startAccessor,
889889
endAccessor,
890890
allDayAccessor,

src/DateContentRow.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ class DateContentRow extends React.Component {
4848
getRowLimit() {
4949
/* Guessing this only gets called on the dummyRow */
5050
const eventHeight = getHeight(this.eventRowRef.current)
51-
const headingHeight =
52-
this.headingRowRef && this.headingRowRef.current
53-
? getHeight(this.headingRowRef.current)
54-
: 0
51+
const headingHeight = this.headingRowRef?.current
52+
? getHeight(this.headingRowRef.current)
53+
: 0
5554
const eventSpace = getHeight(this.containerRef.current) - headingHeight
5655

5756
return Math.max(Math.floor(eventSpace / eventHeight), 1)

src/DayColumn.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,13 @@ class DayColumn extends React.Component {
3838
this.clearTimeIndicatorInterval()
3939
}
4040

41-
UNSAFE_componentWillReceiveProps(nextProps) {
42-
if (nextProps.selectable && !this.props.selectable) this._selectable()
43-
if (!nextProps.selectable && this.props.selectable)
41+
componentDidUpdate(prevProps, prevState) {
42+
if (!prevProps.selectable && this.props.selectable) this._selectable()
43+
if (prevProps.selectable && !this.props.selectable)
4444
this._teardownSelectable()
4545

46-
this.slotMetrics = this.slotMetrics.update(nextProps)
47-
}
46+
this.slotMetrics = this.slotMetrics.update(this.props)
4847

49-
componentDidUpdate(prevProps, prevState) {
5048
const { getNow, isNow, localizer, date, min, max } = this.props
5149
const getNowChanged = localizer.neq(prevProps.getNow(), getNow(), 'minutes')
5250

src/Month.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class MonthView extends React.Component {
2727
this.state = {
2828
rowLimit: 5,
2929
needLimitMeasure: true,
30+
date: null,
3031
}
3132
this.containerRef = createRef()
3233
this.slotRowRef = createRef()
@@ -35,11 +36,11 @@ class MonthView extends React.Component {
3536
this._pendingSelection = []
3637
}
3738

38-
UNSAFE_componentWillReceiveProps({ date }) {
39-
const { date: propsDate, localizer } = this.props
40-
this.setState({
41-
needLimitMeasure: localizer.neq(date, propsDate, 'month'),
42-
})
39+
static getDerivedStateFromProps({ date, localizer }, state) {
40+
return {
41+
date,
42+
needLimitMeasure: localizer.neq(date, state.date, 'month'),
43+
}
4344
}
4445

4546
componentDidMount() {

src/TimeGrid.js

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ export default class TimeGrid extends Component {
2626
this.gutterRef = createRef()
2727
}
2828

29-
UNSAFE_componentWillMount() {
29+
getSnapshotBeforeUpdate() {
3030
this.calculateScroll()
31-
}
32-
33-
componentDidMount() {
3431
this.checkOverflow()
3532

3633
if (this.props.width == null) {
3734
this.measureGutter()
3835
}
36+
return null
37+
}
3938

39+
componentDidMount() {
4040
this.applyScroll()
4141

4242
window.addEventListener('resize', this.handleResize)
@@ -64,23 +64,7 @@ export default class TimeGrid extends Component {
6464
}
6565

6666
componentDidUpdate() {
67-
if (this.props.width == null) {
68-
this.measureGutter()
69-
}
70-
7167
this.applyScroll()
72-
//this.checkOverflow()
73-
}
74-
75-
UNSAFE_componentWillReceiveProps(nextProps) {
76-
const { range, scrollToTime, localizer } = this.props
77-
// When paginating, reset scroll
78-
if (
79-
localizer.neq(nextProps.range[0], range[0], 'minutes') ||
80-
localizer.neq(nextProps.scrollToTime, scrollToTime, 'minutes')
81-
) {
82-
this.calculateScroll(nextProps)
83-
}
8468
}
8569

8670
handleSelectAlldayEvent = (...args) => {

stories/props/scrollToTime.stories.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ ScrollToTime.args = {
3636
defaultView: Views.WEEK,
3737
events: demoEvents,
3838
localizer: mLocalizer,
39-
scrollToTime: new Date(1972, 0, 1, 10),
39+
scrollToTime: new Date(1972, 0, 1, 22),
4040
}

0 commit comments

Comments
 (0)