Skip to content

Instantly share code, notes, and snippets.

@mariusandra
Created August 7, 2017 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariusandra/63faa5f85075d8070c7ef02c19a6cfbc to your computer and use it in GitHub Desktop.
Save mariusandra/63faa5f85075d8070c7ef02c19a6cfbc to your computer and use it in GitHub Desktop.
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