Last active
June 26, 2021 11:16
-
-
Save Cerwyn/50e2ab371dad7e1fc1c52c56ddd7dec4 to your computer and use it in GitHub Desktop.
preact
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 { html } from 'htm/preact'; | |
| import { createContext } from 'preact'; | |
| import { useLocalStore } from 'mobx-react-lite'; | |
| export const StoreContext = createContext(undefined); | |
| export const StoreProvider = ({ children }) => { | |
| const store = useLocalStore(() => ({ | |
| counter: 0, | |
| setCounter: (number) => { | |
| store.counter = store.counter + number | |
| }, | |
| getCounter: () => { | |
| return store.counter | |
| } | |
| })) | |
| return html` | |
| <${StoreContext.Provider} value=${store}>${children}</${StoreContext.Provider}> | |
| ` | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment