Appendix
Appendix A – Callback ref
React comes with two ways of receiving an element instance via the ref
prop. The easiest one is the one we introduced, the object format. But there's another one called a callback ref that takes a functional format:
function commitAttachRef(fiber, instance) { var ref = fiber.ref; if (ref !== null) { if (typeof ref === 'function') { ref(instance) } else { ref.current = instance } } }
Similarly, this functional format is supported when the DOM element is unmounted:
function commitDetachRef(fiber) { var ref = fiber.ref if (ref !== null) { if (typeof ref === 'function') { ref(null) } else { ...