docs/react-wiki-archive/BestPractices/Deprecation-Guidelines.md
This guide outlines recommendations for deprecating API behavior, particularly related to component props.
An example PR following these steps can be found here: https://github.com/microsoft/fluentui/pull/4811
Ensure snapshot tests exist covering existing props functionality as a reference check against deprecation changes.
Keep the tests using deprecated props named in a file with deprecated suffix, such as PersonaCoin.test.tsx -> PersonaCoin.deprecated.test.tsx.
Copy the test's snapshot output (or ensure it's the same if regenerated.)
Modify existing tests to use new prop.
Add new property to interface.
Optionally, temporarily comment out old prop to help find all uses throughout code base and change. (Some usage will be caught by the deprecation lint rule, but not in all cases.)
Update components that consume property as needed to support both deprecated and new props.
Move deprecated prop to end of interface, update comments with deprecation description and add @deprecated.
/**
* Primary text to display, usually the name of the person.
* @deprecated Use 'text' instead.
*/
primaryText?: string;
Make sure old and new tests pass.
Add call to warnDeprecations in constructor, like:
constructor(props: IPersonaCoinProps) {
super(props);
// 'primaryText' is deprecated and 'text' should be used instead
warnDeprecations('PersonaCoin', props, { 'primaryText': 'text' });
}
warnDeprecations will most likely cause deprecated tests to fail. Override the warning callback as follows:
// or @fluentui/utilities in 8+
import { setWarningCallback } from '@uifabric/utilities';
describe('PersonaCoint', () => {
beforeAll(() => {
// Prevent warn deprecations from failing test
const noOp = () => undefined;
setWarningCallback(noOp);
});
afterAll(() => {
setWarningCallback();
});
// tests ...
});