You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constFancyButton=React.forwardRef((props,ref)=>(<buttonref={ref}className="FancyButton">{props.children}</button>));// You can now get a ref directly to the DOM button:constref=React.createRef();<FancyButtonref={ref}>Click me!</FancyButton>;
好消息,現在 ref.current 會指向 DOM 節點
可以照需求寫 function 去操控 ref.current
constCustomSlick=React.forwardRef((props,ref)=>(<Sliderref={ref}{...setting}>{props.children}</Slider>));// You can now get a ref directly to the DOM button:constref=React.createRef();consthandleClick=()=>{ref.current.stop()}<CustomSlickref={ref}><divonClick={handleClick}>STOP!</div></CustomSlick >;
情境:
當引用了一個共用元件
寫好
<Common>{......children}</Common>
當 children 裡的 event 要去控制
<Common>
這個元素好消息,現在 ref.current 會指向 DOM 節點
可以照需求寫 function 去操控 ref.current
但
console.log('ref', ref)
會是ref {current: null}
但操控沒有問題傳送 ref 到 DOM component
The text was updated successfully, but these errors were encountered: