Skip to content

Instantly share code, notes, and snippets.

@Odonno
Created June 1, 2020 09:33
Show Gist options
  • Save Odonno/59c273006d5c4d5c502b615fe234b5a4 to your computer and use it in GitHub Desktop.
Save Odonno/59c273006d5c4d5c502b615fe234b5a4 to your computer and use it in GitHub Desktop.
State management comparison - mobx - StoreContext
const StoreContext = createContext<TodoList>({} as TodoList);
type StoreContextProviderProps = {
children?: ReactNode;
};
export const StoreProvider = ({ children }: StoreContextProviderProps) => {
const todoList = new TodoList();
return (
<StoreContext.Provider value={todoList}>
{children}
</StoreContext.Provider>
);
};
export const useStore = () => useContext(StoreContext);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment