MCPcopy
hub / github.com/react-hook-form/react-hook-form / register

Function register

src/logic/createFormControl.ts:1444–1543  ·  view source on GitHub ↗
(name, options = {})

Source from the content-addressed store, hash-verified

1442 };
1443
1444 const register: UseFormRegister<TFieldValues> = (name, options = {}) => {
1445 let field = get(_fields, name);
1446 const disabledIsDefined =
1447 isBoolean(options.disabled) || isBoolean(_options.disabled);
1448 const shouldRevalidateRemount =
1449 !_names.registerName.has(name) && field && field._f && !field._f.mount;
1450
1451 set(_fields, name, {
1452 ...(field || {}),
1453 _f: {
1454 ...(field && field._f ? field._f : { ref: { name } }),
1455 name,
1456 mount: true,
1457 ...options,
1458 },
1459 });
1460 _names.mount.add(name);
1461
1462 if (field && !shouldRevalidateRemount) {
1463 _setDisabledField({
1464 disabled: isBoolean(options.disabled)
1465 ? options.disabled
1466 : _options.disabled,
1467 name,
1468 });
1469 } else {
1470 updateValidAndValue(name, true, options.value);
1471 }
1472
1473 return {
1474 ...(disabledIsDefined
1475 ? { disabled: options.disabled || _options.disabled }
1476 : {}),
1477 ...(_options.progressive
1478 ? {
1479 required: !!options.required,
1480 min: getRuleValue(options.min),
1481 max: getRuleValue(options.max),
1482 minLength: getRuleValue<number>(options.minLength) as number,
1483 maxLength: getRuleValue(options.maxLength) as number,
1484 pattern: getRuleValue(options.pattern) as string,
1485 }
1486 : {}),
1487 name,
1488 onChange,
1489 onBlur: onChange,
1490 ref: (ref: HTMLInputElement | null): void => {
1491 if (ref) {
1492 _names.registerName.add(name);
1493 register(name, options);
1494 _names.registerName.delete(name);
1495 field = get(_fields, name);
1496
1497 const fieldRef = isUndefined(ref.value)
1498 ? ref.querySelectorAll
1499 ? (ref.querySelectorAll('input,select,textarea')[0] as Ref) || ref
1500 : ref
1501 : ref;

Callers 15

ComponentFunction · 0.85
AppFunction · 0.85
ComponentFunction · 0.85
AppFunction · 0.85
TestComponentFunction · 0.85
ChildFunction · 0.85
AppFunction · 0.85
WatchAppFunction · 0.85
ParentFunction · 0.85
ChildSecondFunction · 0.85
ComponentFunction · 0.85
ItemFunction · 0.85

Calls 2

_setDisabledFieldFunction · 0.85
updateValidAndValueFunction · 0.85

Tested by 15

ComponentFunction · 0.68
AppFunction · 0.68
ComponentFunction · 0.68
AppFunction · 0.68
TestComponentFunction · 0.68
ChildFunction · 0.68
AppFunction · 0.68
WatchAppFunction · 0.68
ParentFunction · 0.68
ChildSecondFunction · 0.68
ComponentFunction · 0.68
ItemFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…