我正在使用編寫React的JSX style,我試圖訪問此onClickOutside包裝的功能以找出用戶何時單擊。下面是其自述用法:圍繞JSX中的React組件包裝高級組件(HOC)
// How to install: npm install react-onclickoutside --save
// load the High Order Component:
var onClickOutside = require('react-onclickoutside');
// create a new component, wrapped by this onclickoutside HOC:
var MyComponent = onClickOutside(React.createClass({
...,
handleClickOutside: function(evt) {
// ...handling code goes here...
},
...
}));
我試圖訪問在此情況下(JSX)「點擊之外」的功能,但它沒有工作。
import React from 'react';
import OnClickOutside from 'react-onclickoutside';
export default class Menu extends React.Component {
constructor(props){
super(props);
}
render() {
return (
<OnClickOutside>
<ul>
<li>Test 1</li>
<li>Test 2</li>
<li>Test 3</li>
</ul>
</OnClickOutside>
);
}
handleClickOutside(event) {
console.log('Clicked outside.');
}
}
您使用ReactDOM呈現您的應用程序嗎? – QoP
是的,像這樣: http://i.imgur.com/LQ070Ss.png –