Skip to content

Commit

Permalink
Remove deprecated useLoc (#359)
Browse files Browse the repository at this point in the history
* remove deprecated useLoc

* fix in create-wmr and examle

* add changeset for create-wmr

* correctly name the export

* remove useLoc export
  • Loading branch information
JoviDeCroock committed Feb 22, 2021
1 parent a735d19 commit c681137
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-eels-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'preact-iso': major
---

Remove deprecated `useLoc` export
5 changes: 5 additions & 0 deletions .changeset/tall-apes-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-wmr': patch
---

Bump `preact-iso` and use `useLocation`
2 changes: 1 addition & 1 deletion packages/create-wmr/tpl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"react-dom": "preact/compat"
},
"dependencies": {
"preact-iso": "^0.2.0"
"preact-iso": "^1.0.0"
},
"devDependencies": {
"wmr": "^1.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/create-wmr/tpl/public/header.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useLoc } from 'preact-iso/router';
import { useLocation } from 'preact-iso/router';

export default function Header() {
const { url } = useLoc();
const { url } = useLocation();
return (
<header>
<nav>
Expand Down
2 changes: 1 addition & 1 deletion packages/preact-iso/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { Router, LocationProvider, useLoc, useLocation } from './router.js';
export { Router, LocationProvider, useLocation } from './router.js';
export { default as lazy, ErrorBoundary } from './lazy.js';
export { default as hydrate } from './hydrate.js';

Expand Down
2 changes: 0 additions & 2 deletions packages/preact-iso/router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ interface LocationHook {
route: (url: string) => void;
};
export const useLocation: () => LocationHook;
/** @deprecated renamed to useLocation() */
export const useLoc: () => LocationHook;

export const useRoute: () => { [key: string]: string };

Expand Down
7 changes: 3 additions & 4 deletions packages/preact-iso/router.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { h, createContext, Fragment, cloneElement } from 'preact';
import { h, createContext, cloneElement } from 'preact';
import { useContext, useMemo, useReducer, useEffect, useLayoutEffect, useRef } from 'preact/hooks';

const UPDATE = (state, url, push) => {
Expand Down Expand Up @@ -67,7 +67,7 @@ export function LocationProvider(props) {
export function Router(props) {
const [, update] = useReducer(c => c + 1, 0);

const loc = useLoc();
const loc = useLocation();

const { url, path, query } = loc;

Expand Down Expand Up @@ -133,6 +133,5 @@ Router.Provider = LocationProvider;
LocationProvider.ctx = createContext(/** @type {{ url: string, path: string, query: object, route }} */ ({}));
const RouteContext = createContext({});

export const useLoc = () => useContext(LocationProvider.ctx);
export const useLocation = useLoc;
export const useLocation = () => useContext(LocationProvider.ctx);
export const useRoute = () => useContext(RouteContext);
4 changes: 2 additions & 2 deletions packages/wmr/demo/public/header.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useLoc } from './lib/loc.js';
import { useLocation } from './lib/loc.js';

export default function Header() {
const { url }: { url: string } = useLoc();
const { url }: { url: string } = useLocation();
return (
<header>
<nav>
Expand Down
5 changes: 2 additions & 3 deletions packages/wmr/demo/public/lib/loc.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function LocationProvider(props) {
export function Router(props) {
const [, update] = useReducer(c => c + 1, 0);

const loc = useLoc();
const loc = useLocation();

const { url, path, query } = loc;

Expand Down Expand Up @@ -130,6 +130,5 @@ LocationProvider.ctx = createContext(/** @type {{ url: string, path: string, que

const RouteContext = createContext({});

export const useLoc = () => useContext(LocationProvider.ctx);
export const useLocation = useLoc;
export const useLocation = () => useContext(LocationProvider.ctx);
export const useRoute = () => useContext(RouteContext);

0 comments on commit c681137

Please sign in to comment.