Cannot read property layer of undefined when passing a ref to Layer
See original GitHub issuePassing a ref
to Layer to wrap it using body-scroll-lock works with 2.17.2 but fails with 2.17.3
Expected Behavior
It should build and run fine
Actual Behavior
TypeError: Cannot read property 'layer' of undefined
The above error occurred in the <ForwardRef> component:
at /home/esya/Git/oasis-wallet/node_modules/grommet/components/Layer/LayerContainer.js:39:25
at Layer (/home/esya/Git/oasis-wallet/node_modules/grommet/components/Layer/Layer.js:27:23)
at ResponsiveLayer (/home/esya/Git/oasis-wallet/src/app/components/ResponsiveLayer/index.tsx:30:44)
URL, screen shot, or Codepen exhibiting the issue
import { disableBodyScroll, enableBodyScroll } from 'body-scroll-lock'
import { Layer, LayerExtendedProps } from 'grommet'
import { useCallback, useRef } from 'react'
function useRefWithCallback(onMount, onUnmount) {
const nodeRef = useRef(null)
const setRef = useCallback(
node => {
if (nodeRef.current) {
onUnmount(nodeRef.current)
}
nodeRef.current = node
if (nodeRef.current) {
onMount(nodeRef.current)
}
},
[onMount, onUnmount],
)
return setRef
}
/**
* Wraps grommet's layer with body-scroll-lock
* @param props Grommet Layer props
*/
export function ResponsiveLayer(props: LayerExtendedProps) {
const layerRef = useRefWithCallback(
node => disableBodyScroll(node),
node => enableBodyScroll(node),
)
return <Layer {...props} ref={layerRef} />
}
Your Environment
- Grommet version: 2.17.3
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Cannot read properties of undefined (reading 'layers') when ...
I've been trying to get the EffectComposer component to work and tried to update the dependencies of this example from drcmda:
Read more >Uncaught TypeError: Cannot read property 'layer' of undefined
This error occurs when the feature that you are trying to search does not exists. I just messed up with the queries.
Read more >How to Avoid the Infamous "Cannot read properties of ... - Bitovi
That error message is telling you the function is returning undefined implicitly, but its return type does not include undefined in it. Awesome!...
Read more >Cannot read properties of undefined (reading 'length') - TrackJS
This message indicates that our code expects to have an object with a length property, but that object was not present.
Read more >TypeError: Cannot read Property 'push' of Undefined in JS
To solve the "Cannot read property push of undefined" error, use the `Array. ... The method returns true if the passed in value...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
yeah, after upgrade v2.17.3, I have the same problem running test.
The above error occurred in the <ForwardRef> component:
I believe this one is fixed by #5524