How to use ref for component
See original GitHub issueLet’s say I use theme and I want to ref on SideBar
like this
<SideBar ref={(el) => this.SideBar = el}>...</SideBar>
but this cannot be achieve. How to get ref for such component
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Refs and the DOM - React
Refs are created using React.createRef() and attached to React elements via the ref attribute. Refs are commonly assigned to an instance property when...
Read more >A complete guide to React refs - LogRocket Blog
Learn how to use React refs, and why it's important to use them only when React can't handle a function call through its...
Read more >The Complete Guide to useRef() and Refs in React
useRef (initialValue) is a built-in React hook that accepts one argument as the initial value and returns a reference (aka ref). A reference...
Read more >Using refs in React functional components (part 1) - useRef + ...
Refs are simply references to anything, like a DOM node, Javascript value, etc. To create a ref in a functional component we use...
Read more >How to Use React Refs - Ross Bulat - Medium
Refs are created using React.createRef() , and are assigned to class properties. In the above example the ref is named myRef , which...
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 Free
Top 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
@joemcelroy You can’t really do that as the SideBar has some filters as children, and hiding it would remove the children and the corresponding accessors. That could have unexpected results when running a new query and then showing the sidebar
What you do want, though, is to have all the prebuilt components that work like plain “div” elements with custom presets.
This is your current LayoutBuilder :
It doesn’t allow adding style or other attributes. What would be better is something like
With something like this (untested) all the extra props get transfered to the div. So now you can add a ref or
style={{display: 'none'}}
(I wouldn’t recommend using the ref for that, it’s always better to stay in the React world)So I have to produce extra div?