appannie / react-infinite-calendar

✨ Infinite scrolling date-picker built with React, with localization, range selection, themes, keyboard support, and more.
MIT License
20 stars 16 forks source link

Components require updating to use onSelect #31

Open multiwebinc opened 4 years ago

multiwebinc commented 4 years ago

When I set the onSelect attribute, the calendar doesn't work and I get an error in the console. Here is my code:

class MyCalendar extends React.Component {
  state = {};

  handleDateSelect = event => {
    this.setState({
      start: event.start,
      end: event.end,
    });
  }
  render() {
    return (
      <InfiniteCalendar
        Component={withRange(Calendar)}
        onSelect={this.handleDateSelect}
      />
    );
  }
}

Here is the error message:

Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details.

  • Move data fetching code or side effects to componentDidUpdate.
  • If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state
  • Rename componentWillReceiveProps to UNSAFEcomponentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE name will work. To rename all deprecated lifecycles to their new names, you can run npx react-codemod rename-unsafe-lifecycles in your project source folder.

Please update the following components: DefaultCalendar, MonthList, VirtualList

SBoudrias commented 4 years ago

Are you willing to send a PR? This will be the fastest way for us to get this fix out.

The error message explains how to run the codemod to rename the unsafe lifecycle for React 17.

multiwebinc commented 4 years ago

@SBoudrias Are you sure that's how you would prefer to handle it? It sort of seems to me that that's more of a last resort option to just suppress the errors without having to actually fix your insecure code.

Either way, I executed npx react-codemod rename-unsafe-lifecycles and the error still persists.

SBoudrias commented 4 years ago

Yeah, the long term solution is 100% to have a proper refactor to fix those. But I just didn't want to ask too much from you in a PR. But if you're willing to help make this refactoring, I'll be happy to help review/merge/release.

On our side, we'll need to update once we bump our codebase to v17 (not officially released yet). But I'm not sure when that will be; at least not immediately.

multiwebinc commented 4 years ago

I would love to help, but I've literally just started learning React (and ES6, JSX syntax) just a few days ago, so unfortunately it's a bit over my head for now.