0

I am using React Material OnInputChange on Autocomplete. How do I get rid of event and reason, below when not needed? Just trying to remove extra variables from Material UI. See greyed out variables in VSCode Eslint.

Resource: https://mui.com/material-ui/api/autocomplete/

onInputChange={async (
  event: object,
  value: string,
  reason: string,
) => {
  setProcedureCodeLength(value.length);
  if (value.length >= 3) {
    const codes = await getProcedureCodes(
      value,
      undefined,
    );
    setProcedureCodeOptions(codes);
  } else {
    setProcedureCodeOptions([]);
  }
}}

enter image description here

'event', 'reason' is declared but its value is never read.ts(6133)

mattsmith5
  • 540
  • 4
  • 29
  • 67
  • ok, so If I only have an event variable, I can get rid of value variable? How about last variable reason, should I just delete that? thanks cc @dippas – mattsmith5 Jul 10 '22 at 23:47
  • sorry my bad, thats just a warning, you can safely, replace `event` by `_` – dippas Jul 10 '22 at 23:52
  • hi @dippas not sure I fully get it, started learning react few weeks ago, can you write as answer in code, and I can send points? thanks – mattsmith5 Jul 10 '22 at 23:54

1 Answers1

1

In order to stop that warning, you have to change this event: object to _, no need to set type because it will infer its type to React.SyntheticEvent<Element, Event>

For reason: string, just deleted it

It stays like this:

onInputChange={async (_, value: string) => {

See: What is the meaning of an Underscore in javascript function parameter?

dippas
  • 58,591
  • 15
  • 114
  • 126