Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 样式不会传递给自定义组件_Javascript_Reactjs_React Native_Components - Fatal编程技术网

Javascript 样式不会传递给自定义组件

Javascript 样式不会传递给自定义组件,javascript,reactjs,react-native,components,Javascript,Reactjs,React Native,Components,我有一个自定义按钮组件与此代码 import React from 'react'; import { TouchableOpacity, View, Text } from 'react-native'; import PropTypes from 'prop-types'; import styles from './styles'; const CustomBtn = ({props, text, onPress }) => ( <TouchableOpacity

我有一个自定义按钮组件与此代码

import React from 'react';
import { TouchableOpacity, View, Text } from 'react-native';
import PropTypes from 'prop-types';

import styles from './styles';

const CustomBtn = ({props, text, onPress }) => (
    <TouchableOpacity {...props} onPress={onPress}>
        <View style={styles.button}>
             <Text style={styles.text}>{text}</Text>
        </View>
    </TouchableOpacity>
);

CustomBtn = {
  text: PropTypes.string,
  onPress: PropTypes.func,
};

export default CustomBtn;
从“React”导入React;
从“react native”导入{TouchableOpacity,View,Text};
从“道具类型”导入道具类型;
从“./styles”导入样式;
const CustomBtn=({props,text,onPress})=>(
{text}
);
自定义BTN={
text:PropTypes.string,
onPress:PropTypes.func,
};
导出默认CustomBtn;
我想在我的视图中覆盖我写入的组件的样式(边距、填充)

<CustomBtn style={styles.BtnMargin} onPress={this.handlePressLogin} text="Login" />

但是我的自定义按钮不符合样式。如何更改自定义btn的代码以解决此问题?

您使用的代码错误。如果查看签名,您会注意到它接受道具作为参数:

function Welcome(props) {
  return <h1>Hello, {props.name}</h1>;
}
const CustomBtn = (props) => (
    <TouchableOpacity {...props} onPress={props.onPress}>
        <View style={styles.button}>
             <Text style={styles.text}>{props.text}</Text>
        </View>
    </TouchableOpacity>
);