Created
November 4, 2018 19:04
-
-
Save simon-robertson/3e47bce03d8468b71c311c10d40e0b39 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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