Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use ref in function component #386

Open
gitdogogo opened this issue Jul 13, 2020 · 3 comments
Open

how to use ref in function component #386

gitdogogo opened this issue Jul 13, 2020 · 3 comments

Comments

@gitdogogo
Copy link

const fn= ({}: Props) => {
let _drawer = React.useRef();
function close() {
_drawer.current.close();
}
function open() {
_drawer.current.open();
}
return (
<Drawer
styles={drawerStyles}
ref={(ref) => (_drawer.current = ref)}
drawerType="overlay"
openDrawerOffset={0.5}
acceptTap={true}
open={true}
content={}
>


);
};

when i used like this , but it's not worked

@VladosK0k0s
Copy link

In functional component you need to use hook useRef

@mdaniyalaslam
Copy link

mdaniyalaslam commented Apr 14, 2021

use this : ref={_drawer}
instead of ref={(ref) => (_drawer.current = ref)}

@rajAmukhliS
Copy link

rajAmukhliS commented Dec 15, 2022

Hope this will help you

import React, {useRef} from 'react';
...
const Index=()=>{
...
const drawerRef=useRef(null);

function close() {
drawerRef.current.close();
}
function open() {
drawerRef.current.open();
}
...
return(
 <Drawer
       ref={drawerRef}
...
>
....
</Drawer>)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants