UNPKG

1.42 kBTypeScriptView Raw
1/** Reset controlled usage warnings for testing purposes. */
2export declare function resetControlledWarnings(): void;
3export interface IWarnControlledUsageParams<P> {
4 /** ID of the component instance. Used to prevent showing warnings repeatedly. */
5 componentId: string;
6 /** Name of the component class. */
7 componentName: string;
8 /** Current props to evaluate. */
9 props: P;
10 /** Previous props to evaluate (undefined if called in the constructor). */
11 oldProps?: P;
12 /** Name of the prop for the controlled value. */
13 valueProp: keyof P;
14 /** Name of the prop for the uncontrolled initial value. */
15 defaultValueProp: keyof P;
16 /** Name of the change handler prop. */
17 onChangeProp: keyof P;
18 /** Name of the read-only prop. */
19 readOnlyProp?: keyof P;
20}
21/**
22 * Check for and warn on the following error conditions with a form component:
23 * - A value prop is provided (indicated it's being used as controlled) without a change handler,
24 * and the component is not read-only
25 * - Both the value and defaultValue props are provided
26 * - The component is attempting to switch between controlled and uncontrolled
27 *
28 * The messages mimic the warnings React gives for these error conditions on input elements.
29 * The warning will only be displayed once per component ID.
30 */
31export declare function warnControlledUsage<P>(params: IWarnControlledUsageParams<P>): void;