Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated useLoc #359

Merged
merged 5 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);