Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace unsafe deprecated methods #2216

Merged
merged 2 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/BackgroundCells.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class BackgroundCells extends React.Component {
this._teardownSelectable()
}

UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.selectable && !this.props.selectable) this._selectable()
componentDidUpdate(prevProps) {
if (!prevProps.selectable && this.props.selectable) this._selectable()

if (!nextProps.selectable && this.props.selectable)
if (prevProps.selectable && !this.props.selectable)
this._teardownSelectable()
}

Expand Down
8 changes: 4 additions & 4 deletions src/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -877,14 +877,14 @@ class Calendar extends React.Component {
super(...args)

this.state = {
context: this.getContext(this.props),
context: Calendar.getContext(this.props),
}
}
UNSAFE_componentWillReceiveProps(nextProps) {
this.setState({ context: this.getContext(nextProps) })
static getDerivedStateFromProps(nextProps) {
return { context: Calendar.getContext(nextProps) }
}

getContext({
static getContext({
startAccessor,
endAccessor,
allDayAccessor,
Expand Down
7 changes: 3 additions & 4 deletions src/DateContentRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ class DateContentRow extends React.Component {
getRowLimit() {
/* Guessing this only gets called on the dummyRow */
const eventHeight = getHeight(this.eventRowRef.current)
const headingHeight =
this.headingRowRef && this.headingRowRef.current
? getHeight(this.headingRowRef.current)
: 0
const headingHeight = this.headingRowRef?.current
? getHeight(this.headingRowRef.current)
: 0
const eventSpace = getHeight(this.containerRef.current) - headingHeight

return Math.max(Math.floor(eventSpace / eventHeight), 1)
Expand Down
10 changes: 4 additions & 6 deletions src/DayColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ class DayColumn extends React.Component {
this.clearTimeIndicatorInterval()
}

UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.selectable && !this.props.selectable) this._selectable()
if (!nextProps.selectable && this.props.selectable)
componentDidUpdate(prevProps, prevState) {
if (!prevProps.selectable && this.props.selectable) this._selectable()
if (prevProps.selectable && !this.props.selectable)
this._teardownSelectable()

this.slotMetrics = this.slotMetrics.update(nextProps)
}
this.slotMetrics = this.slotMetrics.update(this.props)

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

Expand Down
11 changes: 6 additions & 5 deletions src/Month.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class MonthView extends React.Component {
this.state = {
rowLimit: 5,
needLimitMeasure: true,
date: null,
}
this.containerRef = createRef()
this.slotRowRef = createRef()
Expand All @@ -35,11 +36,11 @@ class MonthView extends React.Component {
this._pendingSelection = []
}

UNSAFE_componentWillReceiveProps({ date }) {
const { date: propsDate, localizer } = this.props
this.setState({
needLimitMeasure: localizer.neq(date, propsDate, 'month'),
})
static getDerivedStateFromProps({ date, localizer }, state) {
return {
date,
needLimitMeasure: localizer.neq(date, state.date, 'month'),
}
}

componentDidMount() {
Expand Down
24 changes: 4 additions & 20 deletions src/TimeGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ export default class TimeGrid extends Component {
this.gutterRef = createRef()
}

UNSAFE_componentWillMount() {
getSnapshotBeforeUpdate() {
this.calculateScroll()
}

componentDidMount() {
this.checkOverflow()

if (this.props.width == null) {
this.measureGutter()
}
return null
}

componentDidMount() {
this.applyScroll()

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

componentDidUpdate() {
if (this.props.width == null) {
this.measureGutter()
}

this.applyScroll()
//this.checkOverflow()
}

UNSAFE_componentWillReceiveProps(nextProps) {
const { range, scrollToTime, localizer } = this.props
// When paginating, reset scroll
if (
localizer.neq(nextProps.range[0], range[0], 'minutes') ||
localizer.neq(nextProps.scrollToTime, scrollToTime, 'minutes')
) {
this.calculateScroll(nextProps)
}
}

handleSelectAlldayEvent = (...args) => {
Expand Down
2 changes: 1 addition & 1 deletion stories/props/scrollToTime.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ ScrollToTime.args = {
defaultView: Views.WEEK,
events: demoEvents,
localizer: mLocalizer,
scrollToTime: new Date(1972, 0, 1, 10),
scrollToTime: new Date(1972, 0, 1, 22),
}