-3
<Editor
{...other}
{this.props.isFocus && ref={input => input && input.focus()} }
/>
上記のコードにはエラーがあります。フォーカスを使用してフォーカスを合わせるが、条件付きでrefを設定する
<Editor
{...other}
{this.props.isFocus && ref={input => input && input.focus()} }
/>
上記のコードにはエラーがあります。フォーカスを使用してフォーカスを合わせるが、条件付きでrefを設定する
コンポーネントに小道具を設定するために、そのようなロジックを実行することはできません。あなたが代わりに次のいずれかを実行できます。
<Editor
{...other}
ref={this.props.isFocus ? (input => input && input.focus()) : null}
/>
または
{this.props.isFocus ? <Editor
{...other}
ref={input => input && input.focus()}
/>
: <Editor {...other} />}
言われていること、私はあなたが適切ref
を使用しているとは思いません。特定の条件の下でのみref
を持つ妥当な理由はないと思います。アプリケーションロジックにかかわらず静的な小道具でなければなりません。
そうでなければref
を間違って使用している可能性がありますが、残りのコードを見ることができないのはどうしてですか?
どのようなエラーが発生しますか? –