1 | import warn from './warn';
|
2 | export default function validateSelectedPropChange(prevSelected, selected) {
|
3 | var uncontrolledToControlled = !prevSelected && selected;
|
4 | var controlledToUncontrolled = prevSelected && !selected;
|
5 | var from, to, precedent;
|
6 |
|
7 | if (uncontrolledToControlled) {
|
8 | from = 'uncontrolled';
|
9 | to = 'controlled';
|
10 | precedent = 'an';
|
11 | } else {
|
12 | from = 'controlled';
|
13 | to = 'uncontrolled';
|
14 | precedent = 'a';
|
15 | }
|
16 |
|
17 | var message = "You are changing ".concat(precedent, " ").concat(from, " typeahead to be ").concat(to, ". ") + "Input elements should not switch from ".concat(from, " to ").concat(to, " (or vice versa). ") + 'Decide between using a controlled or uncontrolled element for the ' + 'lifetime of the component.';
|
18 | warn(!(uncontrolledToControlled || controlledToUncontrolled), message);
|
19 | } |
\ | No newline at end of file |