T
T
timonck2020-04-14 22:29:59
JavaScript
timonck, 2020-04-14 22:29:59

What type for event it is necessary to register?

Good evening, please tell me how to correctly register the type in this case? I use select from material ui. currentTarget.innerText I use to find out what text is in the MenuItem

const handleChange = (event: any) => {
        if (
            event.currentTarget.innerText === 'BALANCE'
        ) {
            setSendForm({...sendForm, balance: event.target.value});
            setCBal(true);
        } else {
            setSendForm({...sendForm, balance: event.target.value});
            setCBal(false);
        }
    };


<Select
     labelId="balance-select-label"
     id="balance-select"
     required
     value={sendForm.balance}
     onChange={handleChange}
     >
      {balances.map((i: UserB, index: number) => (
            <MenuItem key={index} value={i.id}>{i.account}</MenuItem>
))}
</Select>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
rasschitai, 2020-04-14
@rasschitai

event.currentTarget.options[event.currentTarget.selectedIndex].text

D
Dmitry Belyaev, 2020-04-15
@bingo347

type TypescriptInferTheEventTypeForMePlease
    = HTMLSelectElement['addEventListener'] extends ((
        eventName: 'change',
        cb: (event: infer E) => any
    ) => any)
    ? E
    : never;

PS VSCode says it's just an Event

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question