1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/with-rematch/pages/index.js
Bhargav Ponnapalli 5187d142ea Added example for usage with rematch (#4095)
* Usage with rematch

* Run lint fix

* Add counter-display example and readme
2018-04-18 14:03:24 +02:00

39 lines
1.1 KiB
JavaScript

import React, { Component } from 'react'
import { dispatch } from '@rematch/core'
import { initStore } from '../shared/store'
import withRematch from '../shared/utils/withRematch'
import Header from '../shared/components/header'
class Home extends Component {
render () {
return (
<div>
<Header />
<h1> Counter </h1>
<h3>The count is {this.props.counter}</h3>
<p>
<button onClick={this.props.increment}>increment</button>
<button onClick={() => dispatch.counter.increment(1)}>
increment (using dispatch function)
</button>
<button onClick={this.props.incrementBy(5)}>increment by 5</button>
<button onClick={this.props.incrementAsync}>incrementAsync</button>
</p>
<br />
</div>
)
}
}
const mapState = state => ({
counter: state.counter
})
const mapDispatch = ({ counter: { increment, incrementAsync } }) => ({
increment: () => increment(1),
incrementBy: amount => () => increment(amount),
incrementAsync: () => incrementAsync(1)
})
export default withRematch(initStore, mapState, mapDispatch)(Home)