MCPcopy
hub / github.com/react-component/form / saveRef

Function saveRef

src/createBaseForm.js:383–413  ·  view source on GitHub ↗
(name, _, component)

Source from the content-addressed store, hash-verified

381 },
382
383 saveRef(name, _, component) {
384 if (!component) {
385 const fieldMeta = this.fieldsStore.getFieldMeta(name);
386 if (!fieldMeta.preserve) {
387 // after destroy, delete data
388 this.clearedFieldMetaCache[name] = {
389 field: this.fieldsStore.getField(name),
390 meta: fieldMeta,
391 };
392 this.clearField(name);
393 }
394 delete this.domFields[name];
395 return;
396 }
397 this.domFields[name] = true;
398 this.recoverClearedField(name);
399 const fieldMeta = this.fieldsStore.getFieldMeta(name);
400 if (fieldMeta) {
401 const ref = fieldMeta.ref;
402 if (ref) {
403 if (typeof ref === 'string') {
404 throw new Error(`can not set ref string for ${name}`);
405 } else if (typeof ref === 'function') {
406 ref(component);
407 } else if (Object.prototype.hasOwnProperty.call(ref, 'current')) {
408 ref.current = component;
409 }
410 }
411 }
412 this.instances[name] = component;
413 },
414
415 cleanUpUselessFields() {
416 const fieldList = this.fieldsStore.getAllFieldsName();

Callers

nothing calls this directly

Calls 3

getFieldMetaMethod · 0.80
getFieldMethod · 0.80
clearFieldMethod · 0.80

Tested by

no test coverage detected