tonyf
tonyf

Reputation: 35557

Issue with Material-UI Select onChange

I'm using Material-UI select and unable to access select value as I am getting the warning:

index.js:1 Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of Transition which is inside StrictMode. Instead, add a ref directly to the element you want to reference.

Here is the code that I am using as part of my Select:

const [myType, setMyType] = useState('');

<Select
  name="myTypeNm"
  label="Type"
  onChange={(e) => {setMyType(e.target.value)}}
  options={myTypes}
/>

when I attempt to display {myType} on screen, nothing appears.

Is there a fix for this as I seem to be only getting this error when changing material-ui select values?

Upvotes: 3

Views: 3848

Answers (2)

Goutham J.M
Goutham J.M

Reputation: 2194

You have not Provided the Value for select so it cannot pass anything , Update like this it will work


const [myType, setMyType] = useState("");
const options = ["Dog","Cat"]
<Select
  name="myTypeNm"
  label="Type"
  onChange={(e) => {setMyType(e.target.value)}}
  options={options}
  value={myType}
/>

Upvotes: 0

That is a Material UI minor bug. So it's not very important so your code can work normally. You only need ignore it. I recommend you to report it to Material UI Github repository to fix it in the next versions.

Upvotes: 3

Related Questions