1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @flow
    
  8.  */
    
  9. 
    
  10. import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
    
  11. 
    
  12. import {getFiberCurrentPropsFromNode} from './legacy-events/EventPluginUtils';
    
  13. 
    
  14. export default function getListener(
    
  15.   inst: Fiber,
    
  16.   registrationName: string,
    
  17. ): Function | null {
    
  18.   const stateNode = inst.stateNode;
    
  19.   if (stateNode === null) {
    
  20.     // Work in progress (ex: onload events in incremental mode).
    
  21.     return null;
    
  22.   }
    
  23.   const props = getFiberCurrentPropsFromNode(stateNode);
    
  24.   if (props === null) {
    
  25.     // Work in progress.
    
  26.     return null;
    
  27.   }
    
  28.   const listener = props[registrationName];
    
  29. 
    
  30.   if (listener && typeof listener !== 'function') {
    
  31.     throw new Error(
    
  32.       `Expected \`${registrationName}\` listener to be a function, instead got a value of \`${typeof listener}\` type.`,
    
  33.     );
    
  34.   }
    
  35. 
    
  36.   return listener;
    
  37. }