Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
236 views
in Technique[技术] by (71.8m points)

react native - Function Prop works in Web not Android

Just started react-native. So noob here but simple problem

The following idea (but stripped-down version below) works fine in my browser but in Android I get an error about the child function component not recognizing the prop function name. Any ideas on what I should do differently for Android?

Notice the parent has onSquarePress={squarePress} and the child has <TouchableWithoutFeedback onPress={() => props.onSquarePress(props.notation)}>

parent:

import React, { Component, PropTypes } from 'react';
import { Text, View, StyleSheet, TouchableWithoutFeedback } from 'react-native';
import Square from './square';

const squarePress =(notation) => {
  console.log(notation)
}
export default function Board(props) {
  return (
    <View>
      <Square 
      key={..}
      left={xOffset + i * squareSize} 
      top={yOffset + y * squareSize}
      size={squareSize}
      notation={notation}
      onSquarePress={squarePress}
      />
    </View>
  );
}

child

mport React, { Component, PropTypes } from 'react';
import { Text, View, StyleSheet, TouchableWithoutFeedback } from 'react-native';

export default function Square(props) {
  return (
    <TouchableWithoutFeedback
        onPress={() => props.onSquarePress(props.notation)}
        disabled={false}
      >
    <View
      key={props.notation}
    >
    </View>
    </TouchableWithoutFeedback>
  );
}

});

Any ideas would be very appreciated!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...