0

ReactJS TypeError: Cannot read property 'value' of undefined is thrown while accessing this field

alert(event.target.value)

import React , { useState }from 'react';
import {DashboardLayout} from '../components/Layout';
import Select from 'react-select'

const options = [
    { value: 'ami-abc*', label: 'ami-abc' },
    { value: 'ami-xyz*', label: 'ami-xyz' },
]

const DiscoverAMIPage = () => {
    return (
        <DashboardLayout>
            <h2>Discovered AMI</h2>
            <Select
                onChange={handleChange}
                options={options}
            />
        </DashboardLayout>
    )
}

function handleChange(event) {
    alert(event.target.value)
}
export default DiscoverAMIPage;

1 Answer 1

2

onChange in react-select return value not an event: https://react-select.com/props

function handleChange(value) {
  alert(value)
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.