/*! For license information please see 0dff5cba.c26df92e.js.LICENSE.txt */
"use strict";(self.webpackChunkweb_totals=self.webpackChunkweb_totals||[]).push([[421],{10528:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>r,metadata:()=>u,toc:()=>a});var n=s(85893),o=s(11151);const r={sidebar_position:9,title:"useSize",comment:!0,tags:["Reactjs","Custom Hook","useSize"]},i=void 0,u={id:"reactjs/custom-hook/use-size",title:"useSize",description:"",source:"@site/issues/reactjs/custom-hook/use-size.md",sourceDirName:"reactjs/custom-hook",slug:"/reactjs/custom-hook/use-size",permalink:"/issues/reactjs/custom-hook/use-size",draft:!1,unlisted:!1,editUrl:"https://github.com/hunghg255/web-totals/tree/main/issues/reactjs/custom-hook/use-size.md",tags:[{label:"Reactjs",permalink:"/issues/tags/reactjs"},{label:"Custom Hook",permalink:"/issues/tags/custom-hook"},{label:"useSize",permalink:"/issues/tags/use-size"}],version:"current",sidebarPosition:9,frontMatter:{sidebar_position:9,title:"useSize",comment:!0,tags:["Reactjs","Custom Hook","useSize"]},sidebar:"tutorialSidebar",previous:{title:"useWindowSize",permalink:"/issues/reactjs/custom-hook/use-window-size"},next:{title:"useGeolocation",permalink:"/issues/reactjs/custom-hook/use-geolocation"}},c={},a=[];function l(e){const t={code:"code",pre:"pre",...(0,o.a)(),...e.components};return(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-jsx",metastring:"live noInline",live:!0,children:"const useSize = (ref) => {\n  const [size, setSize] = useState({});\n\n  useEffect(() => {\n    if (ref.current == null) return;\n    const observer = new ResizeObserver(([entry]) => setSize(entry.contentRect));\n    observer.observe(ref.current);\n    return () => observer.disconnect();\n  }, []);\n\n  return size;\n};\n\nconst App = () => {\n  const ref = useRef();\n  const size = useSize(ref);\n\n  return (\n    <>\n      <div>{JSON.stringify(size)}</div>\n      <textarea ref={ref}></textarea>\n    </>\n  );\n};\n\nrender(<App />);\n"})})}function m(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(l,{...e})}):l(e)}},75251:(e,t,s)=>{var n=s(67294),o=Symbol.for("react.element"),r=Symbol.for("react.fragment"),i=Object.prototype.hasOwnProperty,u=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function a(e,t,s){var n,r={},a=null,l=null;for(n in void 0!==s&&(a=""+s),void 0!==t.key&&(a=""+t.key),void 0!==t.ref&&(l=t.ref),t)i.call(t,n)&&!c.hasOwnProperty(n)&&(r[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps)void 0===r[n]&&(r[n]=t[n]);return{$$typeof:o,type:e,key:a,ref:l,props:r,_owner:u.current}}t.Fragment=r,t.jsx=a,t.jsxs=a},85893:(e,t,s)=>{e.exports=s(75251)},11151:(e,t,s)=>{s.d(t,{Z:()=>u,a:()=>i});var n=s(67294);const o={},r=n.createContext(o);function i(e){const t=n.useContext(r);return n.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(o):e.components||o:i(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]);