question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property layer of undefined when passing a ref to Layer

See original GitHub issue

Passing 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:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
li5tuncommented, Jun 10, 2021

yeah, after upgrade v2.17.3, I have the same problem running test. The above error occurred in the <ForwardRef> component:

0reactions
MikeKingdomcommented, Aug 23, 2021

I believe this one is fixed by #5524

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found