reactjs - 动态传递 prop 在 React Native 中没有任何值(value)

标签 reactjs react-native

我对原生 react 完全陌生。目前正在探索 FontAwesome 5 pro 图标的 react native 矢量图标。

https://github.com/oblador/react-native-vector-icons

FontAwesome 5 有 3 种类型的图标集,例如常规、实心和浅色。

import Icon from 'react-native-vector-icons/FontAwesome5';

const myIcon1 = <Icon name="comments" size={30} color="#900" />; // Defaults to regular
const myIcon2 = <Icon name="comments" size={30} color="#900" solid />;
const myIcon3 = <Icon name="comments" size={30} color="#900" light />; // Only in FA5 Pro

有什么方法可以动态传递图标类型(浅色、实心)吗?

到目前为止我已经尝试过以下方法:

let iconType = focused ? 'solid' : 'light';

return <Icon name="comments" size={30} color="#900" {...iconType} />;

最佳答案

solid 属性采用一个 boolean 值(如果不传递它,则默认为 false),这意味着

<Icon name="comments" size={30} color="#900" solid />
<Icon name="comments" size={30} color="#900" />

是缩写,

<Icon name="comments" size={30} color="#900" solid={true} />
<Icon name="comments" size={30} color="#900" solid={false} />

对于你的情况,你可以尝试这个

<Icon name="comments" size={30} color="#900" solid={focused} light={!focused} />

关于reactjs - 动态传递 prop 在 React Native 中没有任何值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55153631/

相关文章:

listview - React Native ListView 不会通过单击重新渲染状态更改

reactjs - process.env 环境变量未定义

react-native - 失败的 Prop 类型无效的 Prop 'value'

reactjs - Material 用户界面 : How to change the cursor of a disabled Select field

javascript - React 中输入字段失去焦点

react-native - 使用react-native-paytm时无法发布版本

javascript - 使用 SectionList 和标题 View 在 Y 上进行翻译,在滚动条上创建空白区域 - native react

ios - AppDelegate.m Facebook 和 Twitter handleUrl 函数

reactjs - 如何累积单个请求的解析调用?

reactjs - 在组件更新 redux 存储中 React Native setState