question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

0.16.0: Uncaught TypeError: Cannot read property 'preventDefault' of undefined

See original GitHub issue

Hello,

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:closed
  • Created 6 years ago
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
leifoolsencommented, Nov 14, 2017

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:

  • Webpack3 with Node Express middleware and HMR
  • PostCSS/cssnext/css-modules

Repo here: https://github.com/leifoolsen/webpack2-boilerplate

1reaction
jorgebucarancommented, Nov 10, 2017

@leifoolsen I removed modules from master and will publish later.

This should be the way forward:

const actions = app({
  state: JSON.parse(localStorage.getItem(key)),
  view,
  actions
})

window.addEventListener('beforeunload', () => dispatch.storeState())

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! 🙇

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found