jedireza / hapi-react-views

:package: A hapi view engine for React components
MIT License
231 stars 33 forks source link

React Events? #40

Closed Gattermeier closed 8 years ago

Gattermeier commented 8 years ago

I was trying to add forms and events (onSubmit, onChange, onClick) to a template. It seems those do not get attached to the rendered html output?

import React from 'react'
class Component extends React.Component {
  constructor() {
    super()
    this.state = {clicked: false}
    this.handleClick = this.handleClick.bind(this);
  }
  handleClick() {
    this.setState({clicked: !this.state.clicked})
  }
  render() {
    return (
      <div>
        <form>
          <div onClick={this.handleClick}> Click </div>
        </form>
      </div>
    )
  }
}
export default Component

Any hints?

jedireza commented 8 years ago

Thanks for opening an issue. You'll need to remount on the client side for these events to be attached. Have you seen the universal/isomorphic example?

https://github.com/jedireza/hapi-react-views/tree/master/examples/remount

You should be able to add events/handlers in the components/app.jsx file and they'll get wired up on the client.

Gattermeier commented 8 years ago

I see, that makes sense. Thank you very much!