MCPcopy Create free account
hub / github.com/FormidableLabs/react-swipeable / onRef

Function onRef

src/index.ts:288–310  ·  view source on GitHub ↗
(el: HTMLElement | null)

Source from the content-addressed store, hash-verified

286 };
287
288 const onRef = (el: HTMLElement | null) => {
289 // "inline" ref functions are called twice on render, once with null then again with DOM element
290 // ignore null here
291 if (el === null) return;
292 set((state, props) => {
293 // if the same DOM el as previous just return state
294 if (state.el === el) return state;
295
296 const addState: { cleanUpTouch?: () => void } = {};
297 // if new DOM el clean up old DOM and reset cleanUpTouch
298 if (state.el && state.el !== el && state.cleanUpTouch) {
299 state.cleanUpTouch();
300 addState.cleanUpTouch = void 0;
301 }
302 // only attach if we want to track touch
303 if (props.trackTouch && el) {
304 addState.cleanUpTouch = attachTouch(el, props);
305 }
306
307 // store event attached DOM el for comparison, clean up, and re-attachment
308 return { ...state, el, ...addState };
309 });
310 };
311
312 // set ref callback to attach touch event listeners
313 const output: { ref: typeof onRef; onMouseDown?: typeof onStart } = {

Callers

nothing calls this directly

Calls 1

attachTouchFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…