首页 > 解决方案 > 使用带有 react-select v2 的 Font Awesome 图标?

问题描述

使用:https ://react-select.com/home我一直在尝试以下想法的变体:

 const hex = 'f2bc';
 const char = unescape('%u' + hex);
 <Select
   defaultValue={ label: char, value: 'some-value'}
   ...={...}/>

这是上述尝试的结果:

在此处输入图像描述

标签: reactjsfont-awesomereact-select

解决方案


react-select是灵活的,允许PropTypes.node通过label选项

font-awesome图标可以与应用于 HTMLSpan 元素的 className 一起使用,例如

const labelWithIcon = <span className="fas fa-stroopwafel" />

<Select defaultValue={{ label: labelWithIcon, value: 'some-value' }} />

推荐阅读