Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

60
Views
react-select onChange target value undefined error - in nextjs

I am new to react/nextjs and im getting the error "Cannot read properties of undefined (reading 'value')". I have tried a few different things, like using select as just a html tag, I have searched the react-select document, but can not find anything that helps with this issue.

enter image description here

Here is my code:

import { useState } from 'react';
import Select from 'react-select';      
import styles from '../src/styles/Flex.module.scss'

const FlexSidebarContainer = ({ sidebarProps }) => {

  const options = sidebarProps.options

  const [value, setValue] = useState("")
    
      const handleOptionChange = (e) => {
        let value = e.target.value
        setValue({ value })
      }

      return (
        <form className={styles.form}>
          {options.map((option, index) => {
            return (
              <div key={index} className={styles.form_item}>
                <div className={styles.form_label_wrap}>
                  <Select className={styles.form_item_wrap}
                    onChange={handleOptionChange}
                    options={option.items.map(item => ({ value: item.value, label: item.item }) )}
                    defaultValue={option.items.map(item => ({ label: item.item }) )}
                    instanceId={option.items.map(item => ({ instanceId: item.item }) )}
                  />
                </div>
              </div>
            );
          })}
        </form>
      )
}

export default FlexSidebarContainer
7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

Select is not a HTML tag here and onChange will not work on it. It's a custom component so event will be undefined. Either use a select HTML tag or if you are using custom component namely "Select" then use custom event handler which will be passed as props to Select component.

    <select>
      <option></option>
    </select>
7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.