https://github.com/jossmac/react-deprecate
⚠️ Rename props with deprecation warning
https://github.com/jossmac/react-deprecate
deprecate hoc props react
Last synced: about 1 year ago
JSON representation
⚠️ Rename props with deprecation warning
- Host: GitHub
- URL: https://github.com/jossmac/react-deprecate
- Owner: jossmac
- License: mit
- Created: 2017-12-14T03:40:38.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-26T22:41:32.000Z (over 8 years ago)
- Last Synced: 2025-04-19T19:53:14.704Z (about 1 year ago)
- Topics: deprecate, hoc, props, react
- Language: JavaScript
- Homepage:
- Size: 45.9 KB
- Stars: 13
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# React Deprecate
Higher order component to support old props and warn users about the prop change.
## Install
```bash
yarn add react-deprecate
```
## Usage
```jsx
import React, { Component } from 'react';
import renamePropsWithWarning from 'react-deprecate';
// Your component with the breaking name change
class LibComponent extends Component {
static propTypes = { label: PropTypes.string }
render () {
return {this.props.label};
}
}
// Wrapped, with options `old` --> `new`.
// Optional third argument is a custom message renderer.
export default renamePropsWithWarning(
LibComponent,
{ description: 'label', val: 'value' },
({ componentName, prop, renamedProps }) => 'Your message.'
);
// Old AND new props supported:
// `description/val` mapped to `label/value` with a console warning in Development
class UserComponent extends Component {
render () {
return ;
}
}
```
## License
Copyright © 2017 Joss Mackison. MIT Licensed.