Skip to content

Instantly share code, notes, and snippets.

@Cerwyn
Last active June 26, 2021 11:16
Show Gist options
  • Save Cerwyn/50e2ab371dad7e1fc1c52c56ddd7dec4 to your computer and use it in GitHub Desktop.
Save Cerwyn/50e2ab371dad7e1fc1c52c56ddd7dec4 to your computer and use it in GitHub Desktop.
preact
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