I need to set a state field which I get from an event, but it doesn\'t get set when I pass a function to it. The component and method looks like the following:
With the comment from @thirtydot I got a working solution.
I think it's because setState is "async", so by the time the function you pass to setState is executed (and the event is accessed), the event is no longer around. In the second version, the event is accessed immediately and its currentTarget passed to setState
So I stored the event.currentTarget to a variable and used that as it's explained in the ReactJs Event Pooling
Looks like this and it works
private toggleFilter = (event: any) => {
let target = event.currentTarget;
this.setState((prevState) => ({
isFiltering: !prevState.isFiltering,
anchor: target
}));
}
However this does not explain why event.persist() is not working. I'll accept the answer which explains it.