
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
hoist-react-instance-methods
Advanced tools
Copies specific methods from a child instance to a parent instance
Copies specific methods from a child instance to a parent instance. Can be useful in Higher Order Components.
It's recommented to use Higher Order Components (HOC) over mixins and over context
https://medium.com/@dan_abramov/mixins-are-dead-long-live-higher-order-components-94a0d2f9e750 https://facebook.github.io/react/blog/2016/07/13/mixins-considered-harmful.html https://twitter.com/dan_abramov/status/749715530454622208/photo/1
But sometimes HOC is burdensome
// some fake HOCs
@connectRedux()
@withRouter()
@sthElse()
class MyAwesomeInput extends Component {
focus() {
return this.input.focus();
}
render() {
return (
<label>
<input ref={(input) => this.input = input} />
</label>
);
}
}
class App extends Component {
componentDidMount() {
// WTF!!! This is not an awesome Input!!!
this.awesomeInput.getWrappedInstance().getWrappedInstance().getWrappedInstance().focus();
}
render() {
return (
<MyAwesomeInput ref={(input) => this.awesomeInput = input} />
);
}
}
@hoistReactInstanceMethods(
// get instance
(input) => input.getWrappedInstance().getWrappedInstance().getWrappedInstance(),
// specify method names to be copied
['focus']
)
@connectRedux()
@withRouter()
@sthElse()
class MyAwesomeInput extends Component {
focus() {
return this.input.focus();
}
render() {
return (
<div>
<input ref={(input) => this.input = input} />
</div>
);
}
}
class App extends Component {
componentDidMount() {
// Awesome!
this.awesomeInput.focus();
}
render() {
return (
<MyAwesomeInput ref={(input) => this.awesomeInput = input} />
);
}
}
import hoistReactInstanceMethods from 'hoist-react-instance-methods';
hoistReactInstanceMethods(getInstance, methods)(TargetComponent);
// `getInstance` example:
// const getInstance = (instance) => instance.refs.app;
getInstance (Function): Get the ref element. The only argument instance is the instance of TargetComponent. Should return a component instancemethods ([String]): Specify method names to be copiedA higher-order React component class
yarn add hoist-react-instance-methods
MIT
FAQs
Copies specific methods from a child instance to a parent instance
We found that hoist-react-instance-methods demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.