Created
August 7, 2017 04:57
-
-
Save mariusandra/63faa5f85075d8070c7ef02c19a6cfbc to your computer and use it in GitHub Desktop.
This file contains 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
import React, { Component } from 'react' | |
import PropTypes from 'prop-types' | |
import { kea } from 'kea' | |
@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 | |
}] | |
}) | |
}) | |
export default class Counter extends Component { | |
render () { | |
const { counter } = this.props | |
const { increment, decrement } = this.actions | |
return ( | |
<div> | |
<p>Count: {counter}</p> | |
<button onClick={() => increment(1)}>Increment</button> | |
<button onClick={() => decrement(1)}>Decrement</button> | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment