Skip to content

Commit

Permalink
Use useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Jun 22, 2022
1 parent b55b233 commit 302631f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 29 deletions.
27 changes: 0 additions & 27 deletions src/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,33 +77,6 @@ describe("react location", () => {
});

describe("simple location", () => {
it("should update url location on change", () => {
const location = new SimpleLocation(new URL("http://example.com/test"));

const App = () => {
const { href } = useURL();
return <div>{href}</div>;
};

render(
<Context.Provider value={location}>
<App />
</Context.Provider>,
node
);

const el = node.children[0];

expect(el.nodeName).toEqual("DIV");
expect(el.textContent).toEqual("http://example.com/test");

act(() => location.push("/foo"));
expect(el.textContent).toEqual("http://example.com/foo");

act(() => location.push("#test"));
expect(el.textContent).toEqual("http://example.com/foo#test");
});

it("should render links with simple location", () => {
const location = new SimpleLocation(new URL("http://example.com"));

Expand Down
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useLayoutEffect, useContext, createContext, useState } from "react";
import { useEffect, useContext, createContext, useState } from "react";

/**
* Private location properties.
Expand Down Expand Up @@ -119,7 +119,7 @@ export const Context = createContext(
export function useURL(): URL {
const location = useContext(Context);
const [url, setUrl] = useState(location.url);
useLayoutEffect(() => location.onChange(setUrl), [location]);
useEffect(() => location.onChange(setUrl), [location]);
return url;
}

Expand Down

0 comments on commit 302631f

Please sign in to comment.