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.

[Drawer] Using useRef inside a drawer gives current=null

See original GitHub issue
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

Creating ref pointing to a Drawer or any element within the Drawer returns ref.current=null

Expected Behavior 🤔

I’m expecting to be able to create a ref inside a Drawer and be able for example to scroll to the bottom.

Steps to Reproduce 🕹

Steps:

import React, { useEffect, useRef } from "react";
import Drawer from "@material-ui/core/Drawer";

function Example () {
  const ref = useRef(null);
  useEffect(() => {
    //{current: null}
    console.log(ref);
  }, [ref]);

  return (
    <Drawer open={true}>
      <div ref={ref} style={{
        overflowY: "auto"
      }}>
        Some Content
      </div>
    </Drawer>
  );
}

export default Example;

Context 🔦

I’m trying to create a chat box inside the Drawer, in order to improve CX, I need to scroll down to the bottom when new message are coming. I’m using 3 Grid items inside a container. 1 as header 1 to show the messages (that one that I need to make the auto-scroll) 1 at the bottom for the text field

Your Environment 🌎

Tech Version
Material-UI v4.10.2
React v16.13.1
Browser chrome
etc.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, Jun 16, 2020

Great to hear 😃

0reactions
idirouhabcommented, Jun 16, 2020

apologies @oliviertassinari , I couldn’t answer before. Somehow now it’s working but I don’t know what it was wrong but since I’m not able to reproduce it I’m happy to close the issue.

Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Drawer] Using useRef inside a drawer gives current=null
The issue is present in the latest release. I have searched the issues of this repository and believe that this is not a...
Read more >
ReactJs: Why ref.current returns null when the component is ...
To target it I used useRef and tried to log in the console the result: const checkoutBtnRef = useRef("null"); useEffect(() => { console....
Read more >
How to useRef to fix React performance issues
When either the current cell or open states are updated, it only triggers a re-render for the side drawer component and not any...
Read more >
Building a Drawer Component With React Portals | Let's Build UI
Begin by creating a new file named Drawer.jsx . Import the useRef and useEffect hooks from React and also cn from the classnames...
Read more >
How to Detect a Click Outside of a React Component | by JB
const triggerRef = useRef(null); // optional ... Because the Drawer is being passed a ref from it's parent, Dropdown, it must be rendered ......
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