2

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?

tonyf
  • 34,479
  • 49
  • 157
  • 246
  • 1
    It's a generally harmless error. See [this](https://github.com/mui-org/material-ui/issues/13394) issue. If you are unable to access select value you should add your code here so others can reproduce it and help you. – NearHuscarl Apr 08 '21 at 02:15
  • @NearHuscarl - I added my code to question. Unsure what I am doing wrong? – tonyf Apr 08 '21 at 02:45
  • MUI [`Select`](https://material-ui.com/api/select/) doesn't have `options` props. You need to provide a list of `MenuItem` components as `Select` children. See [this example](https://material-ui.com/components/selects/#simple-select). – NearHuscarl Apr 08 '21 at 02:58

2 Answers2

3

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.

0

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}
/>
Goutham J.M
  • 1,726
  • 12
  • 25