Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
964 views
in Technique[技术] by (71.8m points)

react动态加载的组件怎么绑定ref?

image.png

如上面的图,通过React.createElement方式动态加载的组件,moduleRef.current拿到的值是undefined,
不知道这种情况怎么绑定ref呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
return isShow ? <div ref={...}> ref </div> : null

拿 ref 的时候判断一下 current 是否为 null 就行


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...