React Can component mutates Ability handler array when events are fired
See original GitHub issueWhen the ability object is updated the ‘emit’ method is fired and there is a foreach over all the attached handlers for the particular event. See here.
The problem is, the React Can component attaches a handler that calls ‘forceUpdate’ which forces a render and the render method removes the old handler and attaches a new one subsequently mutating the handler array.
A quick fix would be to change the line to the following
handlers.map(h => h).forEach(handler => handler(payload));
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
React.Component
Each component has several “lifecycle methods” that you can override to run code ... Arrays and fragments. ... Binding event handler methods to...
Read more >How To Handle DOM and Window Events with React
In React apps, you can use event handlers to update state data, trigger prop changes, or prevent default browser actions. To do this,...
Read more >When does React re-render after a setState call made inside ...
React batches all setStates done during a React event handler, and applies them just before exiting its own browser event handler. Share.
Read more >React interactivity: Events and state - Learn web development
Instead, we can write a function in <App /> that will expect some data from our form as an input, then pass that...
Read more >Working with App State and Event Listeners in React Native
But when do these “changes” actually occur? Let's examine this next in order to understand exactly when these events are firing. When AppState ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
fixed in
@casl/abiliry@3.0.1
@casl/react@1.0.2
Nice one. Thanks for the quick fix 😃