Undefined is not and object (evaluation _props [registrationName] ')

react native: 0.43.3

The problem only occurs in the Android, iOS system in order. When I touch the TouchableOpacity component, the onTouch function will not execute.

Has anyone found this problem?

I created a calendar with RN. The problem is that when I click the "Day" block on Android devices or emulators, I get the error undefined is not and object (rating "_props [registrationName]"). But it’s normal to click it on iOS devices and emulators. The code for the Day component is as follows:

        <TouchableOpacity style={styles.calendarRowUnit} onPress={() => this.props.onSelect(this.props.date)}>
            <View style={dateWrapperStyle}>
                <Text style={dateTextStyle}>{dateString}</Text>
            </View>
        </TouchableOpacity>

And error image: iamge error information

, "" . , , , . , , , 0,43.3.

+6
2
/**
   * @param {object} inst The instance, which is the source of events.
   * @param {string} registrationName Name of listener (e.g. `onClick`).
   * @return {?function} The stored callback.
   */
  getListener: function(inst, registrationName) {
    var listener;

    // TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
    // live here; needs to be moved to a better place soon
    if (typeof inst.tag === 'number') {
      const props = EventPluginUtils.getFiberCurrentPropsFromNode(
        inst.stateNode
      );
      if (!props) {
        // Work in progress.
        return null;
      }
      listener = props[registrationName];
      if (shouldPreventMouseEvent(registrationName, inst.type, props)) {
        return null;
      }
    } else {
      if (typeof inst._currentElement === 'string') {
        // Text node, let it bubble through.
        return null;
      }
      if (!inst._rootNodeID) {
        // If the instance is already unmounted, we have no listeners.
        return null;
      }
      const props = inst._currentElement.props;
      listener = props[registrationName];
      if (shouldPreventMouseEvent(registrationName, inst._currentElement.type, props)) {
        return null;
      }
    }

    invariant(
      !listener || typeof listener === 'function',
      'Expected %s listener to be a function, instead got type %s',
      registrationName,
      typeof listener
    );
    return listener;
  },

, , Text TouchableOpacity number, . , number string, .

:

: <Text>16</Text> : <Text>String(16)</Text>

+15

# 12905 <Text /> RN ​​0.43.x ​​ . : , <Text /> , . :

  • React Native .
  • TypeCast string.

,

  • <Text> {100} </Text> to <Text> {''100} </Text>
  • <Text> {100} </Text> to <Text> {String(100)} </Text>
  • <Text> {100} </Text> to <Text> {(100).toString} </Text>
0

Source: https://habr.com/ru/post/1016852/


All Articles