0

I am getting an error:

Warning: Use the defaultValue or value props on instead of setting selected on .

<Select
  onChange={props.changecompany}
  value={props.currCompany != undefined ? props.currCompany.id : -1}
>
  <option key={'empty'} value={'-1'}>
    None
  </option>
  {mapstructure()}
</Select>;

And here is my mapstructure()

const mapstructure = () => {
  return companies.map((company) => (
    <option key={company.Id.toString()} value={company.Id}>
      {company.Name}
    </option>
  ));
};

I'm still learning so it is probably something fairly obvious, but the google solutions havent seemed to have fixed it. TIA

hotpink
  • 2,882
  • 1
  • 12
  • 15
greg b
  • 13
  • 4
  • See if this can help: [Warning: Use the 'defaultValue' or 'value' props on – Aniket Kolekar May 30 '21 at 10:19
  • Unfortunately it doesn't. I have tried -1 as the defaultValue as well and it still gives the same error. – greg b May 30 '21 at 19:42

1 Answers1

0

Here is what I think:

React throws a warning (not error) because, Material UI is using selected instead of value.
You have done nothing wrong and should not worry about it.
This can be fixed by Material UI itself in the upcoming updates if you raise this issue.

I hope this clears your doubt.

Aniket Kolekar
  • 383
  • 6
  • 19
  • 1
    I have marked as accepted, and believe you are right unless someone else has some reason otherwise. It does behave as expected, I just received that error. – greg b Jun 02 '21 at 16:10