Warning: Use the 'defaultValue' or 'value' props on <select> instead of setting 'selected' on

前端 未结 5 998
陌清茗
陌清茗 2020-12-29 18:11

SCENARIO A user has a dropdown and he selects an option. I want to display that dropdown and make that option a default value which was selected by that use

5条回答
  •  鱼传尺愫
    2020-12-29 18:18

    In an instance where you want to set a placeholder and not have a default value be selected, you can use this option.

          
    

    Here the user is forced to pick an option!

    EDIT

    If this is a controlled component

    In this case unfortunately you will have to use both defaultValue and value violating React a bit. This is because react by semantics does not allow setting a disabled value as active.

     function TheSelectComponent(props){
         let currentValue = props.curentValue || "DEFAULT";
         return(
          
        )
    }
    

提交回复
热议问题