Skip to content

Instantly share code, notes, and snippets.

@yakkomajuri
Created February 21, 2021 15:11
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/4645dc977db755f37b1d492065ff04f9 to your computer and use it in GitHub Desktop.
Save yakkomajuri/4645dc977db755f37b1d492065ff04f9 to your computer and use it in GitHub Desktop.
import React, { useState } from 'react'
import { useValues, useActions } from 'kea'
import { counterLogic } from './counterLogic'
import './style.css'
export const Counter = () => {
const { count } = useValues(counterLogic)
const { incrementCounter, decrementCounter, updateCounter } = useActions(counterLogic)
const [inputValue, setInputValue] = useState(0)
return (
<div>
<h3>{count}</h3>
<div>
<button onClick={incrementCounter}>+</button>
<button onClick={decrementCounter}>-</button>
</div>
<br />
<div>
<input type="number" value={inputValue} onChange={(e) => setInputValue(Number(e.target.value))} />
<button onClick={() => updateCounter(inputValue)}>Update Value</button>
</div>
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment