skip to Main Content

Unable to set default value for dynamically generated select dropdown in reactjs

<select className="form-control" placeholder="Category name" name="category" value={course.category} onChange={handleChange}> {categories.map((category) => <option key={category._id} data-id={category._id}>{category.categoryName}</option>)} </select> Setting default value: const handleCourseSubmit = async e => { e.preventDefault() setCourse((prevState) => { return { ...prevState, category: categories[0].categoryName } }) console.log('create.js:: handleCourseSubmit:: data: ', course.category); //prints…

VIEW QUESTION
Back To Top
Search