initInput() — react Function Reference
Architecture documentation for the initInput() function in ReactDOMInput.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD 754de9fa_432c_542e_fa21_08b18b75915b["initInput()"] ebd36fdb_cc70_52b6_9971_bcace1958602["ReactDOMInput.js"] 754de9fa_432c_542e_fa21_08b18b75915b -->|defined in| ebd36fdb_cc70_52b6_9971_bcace1958602 96cf114b_9b89_b174_432c_1584a973fcdd["setInitialProperties()"] 96cf114b_9b89_b174_432c_1584a973fcdd -->|calls| 754de9fa_432c_542e_fa21_08b18b75915b 894d4888_e1c9_cdd6_e0cb_7451b6fba151["hydrateProperties()"] 894d4888_e1c9_cdd6_e0cb_7451b6fba151 -->|calls| 754de9fa_432c_542e_fa21_08b18b75915b 49843596_bcbe_c41c_e960_1ffc711ed1ed["track()"] 754de9fa_432c_542e_fa21_08b18b75915b -->|calls| 49843596_bcbe_c41c_e960_1ffc711ed1ed 14e1dad9_019e_0b6b_45f9_989dc6db3084["toString()"] 754de9fa_432c_542e_fa21_08b18b75915b -->|calls| 14e1dad9_019e_0b6b_45f9_989dc6db3084 7404ee30_0cd4_7886_2806_324f301962c4["getToStringValue()"] 754de9fa_432c_542e_fa21_08b18b75915b -->|calls| 7404ee30_0cd4_7886_2806_324f301962c4 style 754de9fa_432c_542e_fa21_08b18b75915b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/react-dom-bindings/src/client/ReactDOMInput.js lines 206–345
export function initInput(
element: Element,
value: ?string,
defaultValue: ?string,
checked: ?boolean,
defaultChecked: ?boolean,
type: ?string,
name: ?string,
isHydrating: boolean,
) {
const node: HTMLInputElement = (element: any);
if (
type != null &&
typeof type !== 'function' &&
typeof type !== 'symbol' &&
typeof type !== 'boolean'
) {
if (__DEV__) {
checkAttributeStringCoercion(type, 'type');
}
node.type = type;
}
if (value != null || defaultValue != null) {
const isButton = type === 'submit' || type === 'reset';
// Avoid setting value attribute on submit/reset inputs as it overrides the
// default value provided by the browser. See: #12872
if (isButton && (value === undefined || value === null)) {
// We track the value just in case it changes type later on.
track((element: any));
return;
}
const defaultValueStr =
defaultValue != null ? toString(getToStringValue(defaultValue)) : '';
const initialValue =
value != null ? toString(getToStringValue(value)) : defaultValueStr;
// Do not assign value if it is already set. This prevents user text input
// from being lost during SSR hydration.
if (!isHydrating || enableHydrationChangeEvent) {
if (disableInputAttributeSyncing) {
// When not syncing the value attribute, the value property points
// directly to the React prop. Only assign it if it exists.
if (value != null) {
// Always assign on buttons so that it is possible to assign an
// empty string to clear button text.
//
// Otherwise, do not re-assign the value property if is empty. This
// potentially avoids a DOM write and prevents Firefox (~60.0.1) from
// prematurely marking required inputs as invalid. Equality is compared
// to the current value in case the browser provided value is not an
// empty string.
if (isButton || toString(getToStringValue(value)) !== node.value) {
node.value = toString(getToStringValue(value));
}
}
} else {
// When syncing the value attribute, the value property should use
// the wrapperState._initialValue property. This uses:
//
// 1. The value React property when present
// 2. The defaultValue React property when present
// 3. An empty string
if (initialValue !== node.value) {
node.value = initialValue;
}
}
}
if (disableInputAttributeSyncing) {
// When not syncing the value attribute, assign the value attribute
// directly from the defaultValue React property (when present)
if (defaultValue != null) {
node.defaultValue = defaultValueStr;
}
} else {
// Otherwise, the value attribute is synchronized to the property,
// so we assign defaultValue to the same thing as the value property
Domain
Subdomains
Source
Frequently Asked Questions
What does initInput() do?
initInput() is a function in the react codebase, defined in packages/react-dom-bindings/src/client/ReactDOMInput.js.
Where is initInput() defined?
initInput() is defined in packages/react-dom-bindings/src/client/ReactDOMInput.js at line 206.
What does initInput() call?
initInput() calls 3 function(s): getToStringValue, toString, track.
What calls initInput()?
initInput() is called by 2 function(s): hydrateProperties, setInitialProperties.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free