MCPcopy
hub / github.com/facebook/react / hydrateInput

Function hydrateInput

packages/react-dom-bindings/src/client/ReactDOMInput.js:347–381  ·  view source on GitHub ↗
(
  element: Element,
  value: ?string,
  defaultValue: ?string,
  checked: ?boolean,
  defaultChecked: ?boolean,
)

Source from the content-addressed store, hash-verified

345}
346
347export function hydrateInput(
348 element: Element,
349 value: ?string,
350 defaultValue: ?string,
351 checked: ?boolean,
352 defaultChecked: ?boolean,
353): void {
354 const node: HTMLInputElement = (element: any);
355
356 const defaultValueStr =
357 defaultValue != null ? toString(getToStringValue(defaultValue)) : '';
358 const initialValue =
359 value != null ? toString(getToStringValue(value)) : defaultValueStr;
360
361 const checkedOrDefault = checked != null ? checked : defaultChecked;
362 // TODO: This 'function' or 'symbol' check isn't replicated in other places
363 // so this semantic is inconsistent.
364 const initialChecked =
365 typeof checkedOrDefault !== 'function' &&
366 typeof checkedOrDefault !== 'symbol' &&
367 !!checkedOrDefault;
368
369 // Detach .checked from .defaultChecked but leave user input alone
370 node.checked = node.checked;
371
372 const changed = trackHydrated((node: any), initialValue, initialChecked);
373 if (changed) {
374 // If the current value is different, that suggests that the user
375 // changed it before hydration. Queue a replay of the change event.
376 // For radio buttons the change event only fires on the selected one.
377 if (node.type !== 'radio' || node.checked) {
378 queueChangeEvent(node);
379 }
380 }
381}
382
383export function restoreControlledInputState(element: Element, props: Object) {
384 const rootNode: HTMLInputElement = (element: any);

Callers 1

commitHydratedInstanceFunction · 0.90

Calls 4

toStringFunction · 0.90
getToStringValueFunction · 0.90
trackHydratedFunction · 0.90
queueChangeEventFunction · 0.90

Tested by

no test coverage detected