0.16.0: Uncaught TypeError: Cannot read property 'preventDefault' of undefined
See original GitHub issueHello,
I Have the following code, which works fine in 0.15.1:
View snippet:
export const view = (state, actions) =>
<div>
<a href="/" onclick={actions.page}>Home</a>
</div>;
Action snippet
export const actions = {
page: (state, actions, event) => {
event.preventDefault();
return { page: '/foo' };
},
After upgrading to 0.16.0, calling preventDefault results in the following error:
Uncaught TypeError: Cannot read property 'preventDefault' of undefined
at Object.page (http://localhost:8084/app.js:9876:11)
at HTMLAnchorElement.actions.(anonymous function) (http://localhost:8084/app.js:8294:33)
The function in HyperApp that causes the error
function initDeep(state, actions, from, path) {
Object.keys(from || {}).map(function(key) {
if (typeof from[key] === "function") {
actions[key] = function(data) {
// The line that causes the error
var result = from[key]((state = get(path, appState)), actions)
....
}
Are there any breaking changes regarding how events are handled?
Issue Analytics
- State:
- Created 6 years ago
- Comments:17 (11 by maintainers)
Top Results From Across the Web
jquery - Cannot read property 'preventDefault' of undefined in ...
In Console I got following error using e.preventDefault() method I used e as a function parameter
Read more >How to Fix cannot read property preventdefault of undefined
This error is frequently seen when creating a function inside a React.js component. It happens because of an incorrect binding of this ....
Read more >Cannot Read Property 'Preventdefault' Of Undefined In React
When the variable is not defined, JavaScript can not read the undefined variable or property. A similar issue we can find in React...
Read more >I am getting this error cannot read property 'preventdefault' of ...
The most likely cause is that your custom useEffect method - which you haven't shown - is calling the callback function passed as...
Read more >[Solved] Passwordless Error due to error in the documentation
Uncaught TypeError : Cannot read properties of undefined (reading 'requestLoginTokenForUser ... preventDefault(); setLoading(true); Accounts.
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 Free
Top 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
Thanks again for helpful comments and answers. I now have a working demo application built with Hyperapp 0.16.0 (just waiting for the router to catch up), with the following features:
Repo here: https://github.com/leifoolsen/webpack2-boilerplate
@leifoolsen I removed modules from master and will publish later.
This should be the way forward:
And eventually, we may have a dedicated solution for subscriptions, like a function or functions run for each state update that would help you with the storeState step.
Thanks for bearing with us! 🙇