Injects hide and show props into a wrapped component. Currently being used in Guild Wars 2 Armory for tooltip debouncing.
npm install react-debounce-decorator// If using flow, grab the injected props type.
import type { InjectedProps } from 'react-debounce-decorator';
import debounceDecorator from 'react-debounce-decorator';
debounceDecorator(150)(
class View extends Component {
props: InjectedProps;
state: {
message: string,
} = { message: 'is anyone there?' };
hello = () => {
this.props.show(() => this.setState({
message: 'hello!',
}));
};
goodbye = () => {
this.props.hide(() => this.setState({
message: 'goodbye...',
}));
};
render () {
return (
<div onMouseEnter={this.hello} onMouseLeave={this.goodbye}>
{this.state.message}
</div>
);
}
}
)Returns a wrapped component that has injected props show and hide.
Immediately calls callback when called.
Calls callback after the debounce duration has expired.
To run the component in various modes, run the following command then go to http://localhost:6006/.
npm startnpm test