main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
839 bytes
|
Line | |
---|
1 | import * as React from 'react';
|
---|
2 | import { noop } from './misc/util';
|
---|
3 | var useState = React.useState;
|
---|
4 | var useHover = function (element) {
|
---|
5 | var _a = useState(false), state = _a[0], setState = _a[1];
|
---|
6 | var onMouseEnter = function (originalOnMouseEnter) { return function (event) {
|
---|
7 | (originalOnMouseEnter || noop)(event);
|
---|
8 | setState(true);
|
---|
9 | }; };
|
---|
10 | var onMouseLeave = function (originalOnMouseLeave) { return function (event) {
|
---|
11 | (originalOnMouseLeave || noop)(event);
|
---|
12 | setState(false);
|
---|
13 | }; };
|
---|
14 | if (typeof element === 'function') {
|
---|
15 | element = element(state);
|
---|
16 | }
|
---|
17 | var el = React.cloneElement(element, {
|
---|
18 | onMouseEnter: onMouseEnter(element.props.onMouseEnter),
|
---|
19 | onMouseLeave: onMouseLeave(element.props.onMouseLeave),
|
---|
20 | });
|
---|
21 | return [el, state];
|
---|
22 | };
|
---|
23 | export default useHover;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.