использовать родную базовую кнопку с реквизитом - PullRequest
0 голосов
/ 10 июня 2019

Я хочу создать повторно используемый компонент кнопки, но у меня возникли некоторые проблемы. Я вернусь undefined is not an onject evaluting '_nativebase.stylrsheetcreate'. Я пытался уничтожить onPress и название, но не повезло. Может кто-нибудь дать четкое объяснение, как решить эту проблему? спасибо

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,
    }
});

для визуализации

<StyledButton
title='Cancel'
onPress={this.somefunction}

/>

1 Ответ

1 голос
/ 10 июня 2019

Удалить 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,
  }
});
...