Last active
April 15, 2021 04:10
-
-
Save UpperCod/eac614b763521c65c75989175693f8d0 to your computer and use it in GitHub Desktop.
Functional behavior
This file contains hidden or 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 { useCounter } from "./use-counter.js"; | |
function component() { | |
const count = useCounter("count"); | |
return ( | |
<host> | |
<button onclick={count.increment}>+</button> | |
<strong>{count.value}</strong> | |
<button onclick={count.decrement}>-</button> | |
</host> | |
); | |
} | |
component.props = { | |
count: { type: Number, value: 0 }, | |
}; |
This file contains hidden or 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 { useProp } from "atomico"; | |
const increment = (value) => value + 1; | |
const decrement = (value) => value - 1; | |
export function useCounter(prop) { | |
const [value, setValue] = useProp(prop); | |
return { | |
value, | |
increment: () => setValue(increment), | |
decrement: () => setValue(decrement), | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment