hyperapp-router icon indicating copy to clipboard operation
hyperapp-router copied to clipboard

Cannot read property 'name' of undefined

Open s0kil opened this issue 6 years ago • 1 comments

Getting error when going to /edge

import { Link, Route, Switch, location } from "@hyperapp/router";

import welcome from "./views/welcome";
import edge from "./views/edge";

const routes = (state, actions) =>
  Switch({}, [
    Route({ path: "/", render: welcome }),
    Route({ path: "/edge", render: edge })
  ]);

export default routes;

s0kil avatar Jan 30 '18 12:01 s0kil

If you're using a named instance, like const main = app(state, actions, view, document.body) I was having a similar issue and had to pass in main instead of state:

import { h, app } from 'hyperapp'
import { Link, Route, location } from '@hyperapp/router'
import { div, p, ul, li } from '@hyperapp/html'

const Home = () => p('Hello, World!')
const Ryan = main => p(`Hello, ${state.name}!`)

const state = {
  location: location.state,
  name: 'Ryan'
}

const actions = {
  location: location.actions,
  speak: state => console.log('Hi')
}

const view = (state, actions) => div([
  ul([
    li([ Link({ to: '/' }, 'Home') ]),
    li({ onclick: actions.speak }, [ Link({ to: '/ryan' }, 'Ryan') ])
  ]),
  Route({ path: '/', render: Home }),
  Route({ path: '/ryan', render: Ryan})
])

const main = app(state, actions, view, document.body)
const unsubscribe = location.subscribe(main.location)

ryanford avatar Mar 25 '18 15:03 ryanford