嗨,我不明白爲什麼我的onclick函數不起作用。我的函數來創建自己運行時間2在頁面加載但不是當我點擊按鈕爲什麼我的onclick函數在反應中不起作用
import React, { Component, PropTypes } from 'react';
import { createContainer } from 'meteor/react-meteor-data';
import { Topics } from '../api/topic.js';
import Topic from './Topic.jsx';
class AppCreate extends Component {
render(){
return(
<div className="container">
<form>
<input type="text" placeholder="donnez un nom a votre Topic" className="topic"></input>
<input type="button" value="Créer" onClick={this.create()}></input>
</form>
</div>
);
}
create(e){
{var test = document.getElementsByClassName("topic").value;
console.log(test);}
}
}
AppCreate.propTypes = {
topics: PropTypes.array.isRequired
};
export default createContainer(() => {
return {
topics: Topics.find({}).fetch(),
};
}, AppCreate);
[React onClick函數在渲染時觸發]可能重複(https://stackoverflow.com/questions/33846682/react-onclick-function-fires-on-render) –