LoginSignup
1
0

onKeyUpでe.target.selectionStartの型が見つからない対処

Posted at

問題点

以下のようなコードがあるとき、onKeyUp内のe.target.selectionStartのみ型エラーが生じる

 <MainTextarea
        text={text}
        onChange={e => {
          setText(e.target.value);
          setSelectionStart(e.target.selectionStart);
        }}
        onFocus={e => {
          setSelectionStart(e.target.selectionStart);
        }}
        onKeyUp={e => {
          setSelectionStart(e.target.selectionStart);
        }}
      />

image.png

解決方法

e.tareget.selectionStartではなくe.currentTarget.selectionStartを使用する

参考

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0