inject -> useStores

https://mobx-react.js.org/recipes-migration\#hooks-to-the-rescue
This commit is contained in:
Tom Moor committed 2020-08-22 23:29:45 -07:00
1 parent 0bb9fb8fff
commit c0db3ea02a
2 files changed
+13 -5

No files matched your search

+5 -5
View File
@@ -1,25 +1,25 @@
// @flow
import { observer, inject } from "mobx-react";
import { observer } from "mobx-react";
import { CloseIcon, MenuIcon } from "outline-icons";
import * as React from "react";
import { withRouter } from "react-router-dom";
import type { Location } from "react-router-dom";
import styled from "styled-components";
import breakpoint from "styled-components-breakpoint";
import UiStore from "stores/UiStore";
import Fade from "components/Fade";
import Flex from "components/Flex";
import usePrevious from "hooks/usePrevious";
import useStores from "hooks/useStores";
let firstRender = true;
type Props = {
children: React.Node,
location: Location,
ui: UiStore,
};
function Sidebar({ location, children, ui }: Props) {
function Sidebar({ location, children }: Props) {
const { ui } = useStores();
const previousLocation = usePrevious(location);
React.useEffect(() => {
@@ -112,4 +112,4 @@ const Toggle = styled.a`
`};
`;
export default withRouter(inject("ui")(observer(Sidebar)));
export default withRouter(observer(Sidebar));
+8
View File
@@ -0,0 +1,8 @@
// @flow
import { MobXProviderContext } from "mobx-react";
import * as React from "react";
import RootStore from "stores";
export default function useStores(): typeof RootStore {
return React.useContext(MobXProviderContext);
}