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

前端 未结 5 1010
陌清茗
陌清茗 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:43

    With Hooks and useState

    Use defaultValue to select the default value.

        const statusOptions = [
            { value: 1, label: 'Publish' },
            { value: 0, label: 'Unpublish' }
        ];
        const [statusValue, setStatusValue] = useState('');
        const handleStatusChange = e => {
            setStatusValue(e.value);
        }
    
    return(
    <>
    
                            
        
    提交评论

提交回复
热议问题