React-Select - Replacing Components for custom option content

前端 未结 3 1187
渐次进展
渐次进展 2021-02-02 12:51

Using React-Select (version 2) I would like to have custom designed (select) options.

The documentation suggests that Replacing Components would be a method that I could

3条回答
  •  执笔经年
    2021-02-02 13:33

    Generally, you indeed want to use formatOptionLabel prop (no extra component). But in case you don't, you may override the Option component this way:

    import Select, { components } from 'react-select';
    
    const CustomOption = ({ children, ...props }) => {
      return (
        
          
          {children}
        
      );
    };
    
    function App() {
      return (
        
                            
        
    提交评论

提交回复
热议问题