Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
オープン
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 11.8k
- フォーク
- 7.9k
- 平均マージ
- 1日 11時間
- マージ済み PR(30日)
- 11
説明
I have the folowing part of code:
private rootRef = React.createRef<HTMLDivElement>();
const target = (
<div>
<Icon design='accepted' size='xl' />
</div>
);
return (
<React.Fragment>
{React.cloneElement(target, {
ref: this.rootRef,
onMouseOver: this.handleMouseOver,
onMouseLeave: this.handleMouseLeave,
})}
{open && this.renderTooltip()}
</React.Fragment>
);
When target with div element (or any other instead of div) everything is ok, but when target is:
const target = (
<Icon design='accepted' size='xl' />
);
I get error: Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
Icon is a span element inside of which is svg.
I will be very appreciate for any help.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リポジトリのファイル、テスト、ドキュメントページは指定されていません。まず、再現例で示されている React.cloneElement と ref の挙動を確認し、その後、既存の react.dev のページに明確化が必要かどうかを特定してください。完了とするには、範囲が明確なドキュメントの変更と、更新された説明を検証する方法が必要です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, react
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 20/100