【问题标题】:How to add parameters to a React object?如何向 React 对象添加参数?
【发布时间】:2023-02-15 16:43:27
【问题描述】:

我有一个错误的共享样式:

export const modalStyle(height)= {  // <-- Whats the syntax for adding parameter here?
    width:MODAL_WIDTH,
    height:height,
    backgroundColor:color_theme_light.mainGreen,
    borderRadius:22,
    justifyContent:"center",
    alignItems:"center",
    
    shadowColor: "#000",
    shadowOffset: {
      width: 0,
      height: 1,
    },
    shadowOpacity: 0.20,
    shadowRadius: 1.41,
    elevation: 2
}

我怎样才能给它添加一个参数,所以当我调用这个样式时我可以动态地改变高度?

import {modalStyle} from './modalStyles'

<View style={modalStyle(40)}>
 ...
</View>

【问题讨论】:

    标签: javascript reactjs react-native styles


    【解决方案1】:

    使用箭头函数:

    export const modalStyle = (height) => {}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-16
      • 1970-01-01
      • 2018-07-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多