与道具一起使用本机基本按钮

时间:2019-06-10 03:13:36

标签: reactjs react-native native-base

我想创建一个可重复使用的按钮组件,但是我遇到了一些问题。我回来了==。我试图破坏onPress和标题,但没有运气。有人可以就如何解决这个问题给出明确的解释吗?谢谢

undefined is not an onject evaluting '_nativebase.stylrsheetcreate'

渲染

import React from 'react';
import {  View, Text, Button, StyleSheet } from 'native-base';

export const StyledButton = props => {
    return (
        <View style={styles.button}>
            <Button
                block
                full
                bordered
                light
                onPress={this.props.onPress}
            >
                <Text
                    style={{
                        color: '#FFFFFF',
                    }}
                >
                    {this.props.title}
                </Text>
                {this.props.children}
            </Button>
        </View>
    );
};


const styles = StyleSheet.create({
    button: {
        flex: 1,
        padding: 10,
    }
});

1 个答案:

答案 0 :(得分:1)

使用this删除props.someprop

import React from 'react';
import { StyleSheet } from 'react-native';
import { View, Text, Button } from 'native-base';

export const StyledButton = props => {
  return (
    <View style={styles.button}>
      <Button block full bordered light onPress={props.onPress}>
        <Text
          style={{
            color: '#FFFFFF',
          }}>
          {props.title}
        </Text>
        {props.children}
      </Button>
    </View>
  );
};

const styles = StyleSheet.create({
  button: {
    flex: 1,
    padding: 10,
  }
});