Skip to content

Instantly share code, notes, and snippets.

@simon-robertson
Created November 4, 2018 19:04
Show Gist options
  • Save simon-robertson/3e47bce03d8468b71c311c10d40e0b39 to your computer and use it in GitHub Desktop.
Save simon-robertson/3e47bce03d8468b71c311c10d40e0b39 to your computer and use it in GitHub Desktop.
//
// component class
//
import React from 'react'
import { CounterTest } from 'app/stores'
export class Example extends React.Component {
componentDidMount() {
CounterTest.subscribe(this)
}
componentWillUnmount() {
CounterTest.unsubscribe(this)
}
render() {
return <div onClick={ () => CounterTest.increase() }>{ CounterTest.value }</div>
}
}
//
// function component (using 16.7.0-alpha hook api)
//
import React from 'react'
import { CounterTest, useStore } from 'app/stores'
export const Example = () => {
useStore(CounterTest)
return <div onClick={ () => CounterTest.increase() }>{ CounterTest.value }</div>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment