Skip to content

Instantly share code, notes, and snippets.

@yakkomajuri
Created February 21, 2021 15:15
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 yakkomajuri/d3c201319382d7f201089396ccbe0615 to your computer and use it in GitHub Desktop.
Save yakkomajuri/d3c201319382d7f201089396ccbe0615 to your computer and use it in GitHub Desktop.
import { kea } from 'kea'
import { counterLogicType } from './counterLogicType'
export const counterLogic = kea<counterLogicType>({
actions: {
incrementCounter: true, // https://kea.js.org/docs/guide/concepts#actions
decrementCounter: true, // true is shorthand for a function that doesn't take any arguments
updateCounter: (newValue: number) => ({ newValue }),
},
reducers: {
count: [
0, // default value
{
incrementCounter: (state) => state + 1,
decrementCounter: (state) => state - 1,
updateCounter: (_, { newValue }) => newValue, // ignore the state, set new value
},
],
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment