Decorator shields public methods of a class
See original GitHub issueAfter decorating a dropdown:
@withStyles(style)
export default class UiDropdown
I’m no longer able to reference it:
this.dropdownRef.show()
results in TypeError: this.dropdownRef.show is not a function
Issue Analytics
- State:
- Created 7 years ago
- Comments:34 (1 by maintainers)
Top Results From Across the Web
Can a decorator of an instance method access the class?
The method decorator marks the method as one that is of interest by adding a "use_class" attribute - functions and methods are also...
Read more >4. Decorator Pattern - ActionScript 3.0 Design Patterns [Book]
The public method inherited from the Decorator class must be set up using the override statement. ... and the combatants have different weapons...
Read more >Using the Decorator pattern to add public methods to an object
The decorator pattern prevents the explosion by wrapping around the base window class' existing public methods. The decorator pattern ideally ...
Read more >Decorating Methods defined in a Class With Python
To decorate a method in a class, first use the '@' symbol followed by the name of the decorator function. A decorator is...
Read more >Solved We have previously written decorators for Animal
Question: We have previously written decorators for Animal and Comparator classes, but the decorator pattern works for any class hierarchy, although the more ......
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
@ljharb let me repeat it once again 😃 it fails in both cases
<UiDropdown ref={...} />
—ref
points to withStyles HOC when I expect it to point to the wrapped component i.e. UiDropdown.And if I look here, I’m not able how find any ref delegation https://github.com/airbnb/react-with-styles/blob/master/src/withStyles.jsx#L45
I suggest it can be solved this way:
The only mechanism for communication is props.
ref
is a special prop that violates encapsulation. If you use literally any other prop name besides “key” or “ref”, I would expect what you want to work just fine.