[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:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top 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 >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
Great to hear 😃
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.