Created
November 17, 2019 09:57
-
-
Save webmasterdevlin/5bc1443701f1c9dc6b530ec9b397e3a2 to your computer and use it in GitHub Desktop.
Computed
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 React, { createContext } from "react"; | |
import { useLocalStore } from "mobx-react-lite"; | |
import { | |
deleteHero, | |
getHeroById, | |
getHeroes, | |
postHero, | |
putHero | |
} from "./hero-service"; | |
export const HeroProvider = ({ children }) => { | |
const store = useLocalStore(() => ({ | |
/*observables here*/ | |
/*actions here*/ | |
/*computed values i.e. derived state*/ | |
get totalHeroes() { | |
return store.heroes.length; | |
} | |
})); | |
return <heroContext.Provider value={store}>{children}</heroContext.Provider>; | |
}; | |
export const heroContext = createContext(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment