/*! For license information please see ce34d402.cf3811d6.js.LICENSE.txt */
"use strict";(self.webpackChunkweb_totals=self.webpackChunkweb_totals||[]).push([[3727],{55446:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>f,frontMatter:()=>o,metadata:()=>u,toc:()=>i});var s=n(85893),r=n(11151);const o={sidebar_position:14,title:"useMergeRefs",comment:!0,tags:["Reactjs","Custom Hook","useMergeRefs"]},a=void 0,u={id:"reactjs/custom-hook/use-merge-ref",title:"useMergeRefs",description:"",source:"@site/issues/reactjs/custom-hook/use-merge-ref.md",sourceDirName:"reactjs/custom-hook",slug:"/reactjs/custom-hook/use-merge-ref",permalink:"/issues/reactjs/custom-hook/use-merge-ref",draft:!1,unlisted:!1,editUrl:"https://github.com/hunghg255/web-totals/tree/main/issues/reactjs/custom-hook/use-merge-ref.md",tags:[{label:"Reactjs",permalink:"/issues/tags/reactjs"},{label:"Custom Hook",permalink:"/issues/tags/custom-hook"},{label:"useMergeRefs",permalink:"/issues/tags/use-merge-refs"}],version:"current",sidebarPosition:14,frontMatter:{sidebar_position:14,title:"useMergeRefs",comment:!0,tags:["Reactjs","Custom Hook","useMergeRefs"]},sidebar:"tutorialSidebar",previous:{title:"usePrevious",permalink:"/issues/reactjs/custom-hook/use-previous"},next:{title:"useMemoByObjectVariables",permalink:"/issues/reactjs/custom-hook/useMemoByObjectVariables"}},c={},i=[];function l(e){const t={code:"code",pre:"pre",...(0,r.a)(),...e.components};return(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-jsx",metastring:"live noInline",live:!0,children:"function mergeRefs(...args) {\n  let a = arguments.length,\n    c = new Array(a);\n  for (let d = 0; d < a; d++) c[d] = arguments[d];\n  return function (a) {\n    c.forEach(function (c) {\n      if (c == null) return;\n      if (typeof c === 'function') {\n        c(a);\n        return;\n      }\n      if (typeof c === 'object') {\n        c.current = a;\n        return;\n      }\n      console.warn(\n        'mergeRefs cannot handle Refs of type boolean, number or string, received ref ' + String(c),\n        'comet_ui',\n      );\n    });\n  };\n}\n\nfunction useMergeRefs(...args) {\n  const a = arguments.length;\n  const c = new Array(a);\n  for (let d = 0; d < a; d++) {\n    c[d] = arguments[d];\n  }\n  return React.useMemo(function () {\n    return mergeRefs.apply(void 0, c);\n  }, [c].flat());\n}\n\nconst App = () => {\n  const previousCount = useMergeRefs(count);\n\n  return <>useMergeRefs</>;\n};\n\nrender(<App />);\n"})})}function f(e={}){const{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},75251:(e,t,n)=>{var s=n(67294),r=Symbol.for("react.element"),o=Symbol.for("react.fragment"),a=Object.prototype.hasOwnProperty,u=s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function i(e,t,n){var s,o={},i=null,l=null;for(s in void 0!==n&&(i=""+n),void 0!==t.key&&(i=""+t.key),void 0!==t.ref&&(l=t.ref),t)a.call(t,s)&&!c.hasOwnProperty(s)&&(o[s]=t[s]);if(e&&e.defaultProps)for(s in t=e.defaultProps)void 0===o[s]&&(o[s]=t[s]);return{$$typeof:r,type:e,key:i,ref:l,props:o,_owner:u.current}}t.Fragment=o,t.jsx=i,t.jsxs=i},85893:(e,t,n)=>{e.exports=n(75251)},11151:(e,t,n)=>{n.d(t,{Z:()=>u,a:()=>a});var s=n(67294);const r={},o=s.createContext(r);function a(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function u(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]);