MCPcopy Create free account
hub / github.com/react/react / trackHydrated

Function trackHydrated

packages/react-dom-bindings/src/client/inputValueTracking.js:132–160  ·  view source on GitHub ↗
(
  node: ElementWithValueTracker,
  initialValue: string,
  initialChecked: boolean,
)

Source from the content-addressed store, hash-verified

130}
131
132export function trackHydrated(
133 node: ElementWithValueTracker,
134 initialValue: string,
135 initialChecked: boolean,
136): boolean {
137 // For hydration, the initial value is not the current value but the value
138 // that we last observed which is what the initial server render was.
139 if (getTracker(node)) {
140 return false;
141 }
142
143 let valueField: 'checked' | 'value';
144 let expectedValue;
145 if (isCheckable(node)) {
146 valueField = 'checked';
147 // eslint-disable-next-line react-internal/safe-string-coercion
148 expectedValue = '' + (initialChecked: any);
149 } else {
150 valueField = 'value';
151 expectedValue = initialValue;
152 }
153 const currentValue =
154 // eslint-disable-next-line react-internal/safe-string-coercion
155 '' +
156 (// $FlowFixMe[prop-missing]
157 node[valueField]: any);
158 node._valueTracker = trackValueOnNode(node, valueField, expectedValue);
159 return currentValue !== expectedValue;
160}
161
162export function updateValueIfChanged(node: ElementWithValueTracker): boolean {
163 if (!node) {

Callers 2

hydrateTextareaFunction · 0.90
hydrateInputFunction · 0.90

Calls 3

getTrackerFunction · 0.85
isCheckableFunction · 0.85
trackValueOnNodeFunction · 0.85

Tested by

no test coverage detected