admin管理员组文章数量:1434916
I have declared a arrow function inside react ponent. inside this i have logged a value but it shows error. I am new in react so please help me out.
Where I have declared the function
class DeliveryPage extends Component{
onChange : (event) => { console.log('change', event.target.value); }
}
I have invoked the function here
<ComboBox
data={source}
onChange={this.onChange}
onFilterChange={this.onFilterChange}
filterable={true}
/>
Then i have changed my code to
onChange = (event) => { console.log('change', event.target.value); }
I have declared a arrow function inside react ponent. inside this i have logged a value but it shows error. I am new in react so please help me out.
Where I have declared the function
class DeliveryPage extends Component{
onChange : (event) => { console.log('change', event.target.value); }
}
I have invoked the function here
<ComboBox
data={source}
onChange={this.onChange}
onFilterChange={this.onFilterChange}
filterable={true}
/>
Then i have changed my code to
onChange = (event) => { console.log('change', event.target.value); }
Share
Improve this question
edited May 5, 2019 at 7:43
Tanveer Hasan
asked May 5, 2019 at 7:34
Tanveer HasanTanveer Hasan
3431 gold badge5 silver badges17 bronze badges
2 Answers
Reset to default 5onChange : (event) => { console.log('change', event.target.value); }
This is incorrect syntax, it should be:
onChange = (event) => { console.log('change', event.target.value); }
If the Arrow Functions don't work, then you most likely don't have the proposal-class-properties functionally, which can be installed via the following Babel Plugin: https://babeljs.io/docs/en/babel-plugin-proposal-class-properties.
Otherwise, try this method similar to this:
class DeliveryPage extends Component{
constructor(props) {
super(props);
this.onChange = this.onChange.bind(this);
}
onChange(event) {
console.log('change', event.target.value);
}
}
You should be trying this
class DeliveryPage extends Component{
onChange = (event) => {
console.log('change', event.target.value);
}
}
本文标签: javascriptconsolelog not working in arrow functionStack Overflow
版权声明:本文标题:javascript - console.log not working in arrow function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745632153a2667340.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论