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-kea/pages/index.js
Henrik Wenz 60b1d26f1f Update with-kea example (#5259)
- updates transform-decorators-legacy
- updates with-next-redux-wrapper
2018-09-23 16:01:37 +02:00

41 lines
986 B
JavaScript

import React from 'react'
import PropTypes from 'prop-types'
import { kea } from 'kea'
@kea({
path: () => ['kea'],
actions: () => ({
increment: amount => ({ amount }),
decrement: amount => ({ amount })
}),
reducers: ({ actions }) => ({
counter: [
0,
PropTypes.number,
{
[actions.increment]: (state, payload) => state + payload.amount,
[actions.decrement]: (state, payload) => state - payload.amount
}
]
}),
selectors: ({ selectors }) => ({
doubleCounter: [
() => [selectors.counter],
counter => counter * 2,
PropTypes.number
]
})
})
export default class App extends React.Component {
render () {
return (
<div>
<p>Double Counter: {this.props.doubleCounter}</p>
<button type='button' onClick={() => this.actions.increment(1)}>Increment</button>
<button type='button' onClick={() => this.actions.decrement(1)}>Decrement</button>
</div>
)
}
}