Reputation: 777
I'm implementing onChange
method to delete uploaded image.
But compile error occurs, so I want to know solution.
front: React
css: semantic-ui-react
constructor(props: {}) {
super(props);
this.state = {
title: '',
content: '',
redirect: false,
files: [],
};
this.handleRemove = this.handleRemove.bind(this);
}
handleRemove() {
// some code
}
render() {
return (
<List>
{(this.state.files || []).map(function(file, i) {
// error occurs at onclick
return <List.Item icon="image" content={file.name} onclick={this.handleRemove}/>;
})}
</List>
);
}
The full soruce code is here:
https://github.com/jpskgc/article/blob/master/client/src/components/Detail.tsx
On the this.handleRemove
, the following error occurs.
I want to resolve this error.
any
'this' implicitly has type 'any' because it does not have a type annotation.ts(2683)
Post.tsx(115, 49): An outer value of 'this' is shadowed by this container.
Upvotes: 1
Views: 3731
Reputation: 8774
You have to use an arrow function within your map function so that 'this' is passed into your map function:
map((file,I) => {...}) Instead of map(function(file,I){})
Upvotes: 3