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

feat!: removed deprecated hooks #395

Merged
merged 2 commits into from
Nov 18, 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
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# History of Changes

## Unreleased

### Breaking Changes

- Removed `useRouteData` in favor of `useLoaderData`
- Removed `usePendingLocation` in favor of `useTransition().location`
- Removed `usePendingFormSubmit` in favor of `useTransition().submission`

## 0.20.0 - Fri Oct 29 2021

### Improvements
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/mdx.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ The following example demonstrates how you might build a simple blog with MDX, i
In `app/routes/index.jsx`:

```tsx
import { useRouteData } from "remix";
import { useLoaderData } from "remix";
import { Link } from "react-router-dom";

// Import all your posts from the app/routes/posts directory. Since these are
Expand Down Expand Up @@ -117,7 +117,7 @@ export function loader() {
}

export default function Index() {
let posts = useRouteData();
let posts = useLoaderData();

return (
<ul>
Expand Down
6 changes: 3 additions & 3 deletions fixtures/gists-app/app/routes/blog/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { HeadersFunction, LinksFunction, LoaderFunction } from "remix";
import { Link, useRouteData, usePendingLocation, json } from "remix";
import { Link, useLoaderData, useTransition, json } from "remix";

import * as helloPost from "./hello-world.mdx";
import * as thirdPost from "./third.md";
Expand Down Expand Up @@ -49,8 +49,8 @@ export let headers: HeadersFunction = ({ loaderHeaders }) => {
};

export default function BlogPosts() {
let locationPending = usePendingLocation();
let { posts } = useRouteData<PostsData>();
let locationPending = useTransition().location;
let { posts } = useLoaderData<PostsData>();

return (
<div data-test-id="/blog">
Expand Down
4 changes: 2 additions & 2 deletions fixtures/gists-app/app/routes/gists.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Outlet } from "react-router-dom";
import { Link, useLoaderData, usePendingLocation, json } from "remix";
import { Link, useLoaderData, useTransition, json } from "remix";

import Shared from "~/components/Shared";
import stylesHref from "~/styles/gists.css";
Expand Down Expand Up @@ -34,7 +34,7 @@ export let handle = {
};

export default function Gists() {
let locationPending = usePendingLocation();
let locationPending = useTransition().location;
let { users } = useLoaderData();

return (
Expand Down
12 changes: 3 additions & 9 deletions fixtures/gists-app/app/routes/methods.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import * as React from "react";
import type { LoaderFunction, ActionFunction, FormProps } from "remix";
import {
useLoaderData,
usePendingFormSubmit,
Form,
json,
redirect
} from "remix";
import { useLoaderData, useTransition, Form, json, redirect } from "remix";

import stylesHref from "../styles/methods.css";
import { getSession, commitSession } from "../sessionStorage";
Expand Down Expand Up @@ -63,9 +57,9 @@ export default function Methods() {
let [enctype, setEnctype] = React.useState<FormProps["encType"]>(
"application/x-www-form-urlencoded"
);
let pendingFormSubmit = usePendingFormSubmit();
let pendingFormSubmit = useTransition().submission;
let pendingForm = pendingFormSubmit
? Object.fromEntries(pendingFormSubmit.data)
? Object.fromEntries(pendingFormSubmit.formData)
: null;

return (
Expand Down
6 changes: 3 additions & 3 deletions fixtures/tutorial/app/routes/gists.new.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { LinksFunction } from "remix";
import { Form, usePendingFormSubmit } from "remix";
import { Form, useTransition } from "remix";

import styles from "../styles/gists.new.css";

Expand All @@ -8,15 +8,15 @@ export let links: LinksFunction = () => {
};

export default function NewGist() {
let pendingForm = usePendingFormSubmit();
let pendingForm = useTransition().submission;

return (
<>
<h2>New Gist!</h2>
{pendingForm ? (
<div>
<p>
<Loading /> Creating gist: {pendingForm.data.get("fileName")}
<Loading /> Creating gist: {pendingForm.formData.get("fileName")}
</p>
</div>
) : (
Expand Down
33 changes: 1 addition & 32 deletions packages/remix-react/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export function RemixRoute({ id }: { id: string }) {
}

// It's important for the route context to be above the error boundary so that
// a call to `useRouteData` doesn't accidentally get the parents route's data.
// a call to `useLoaderData` doesn't accidentally get the parents route's data.
return (
<RemixRouteContext.Provider value={context}>
{element}
Expand Down Expand Up @@ -1133,11 +1133,6 @@ export function useLoaderData<T = AppData>(): T {
return useRemixRouteContext().data;
}

/**
* @deprecated Use `useLoaderData`
*/
export let useRouteData = useLoaderData;

export function useActionData<T = AppData>(): T | undefined {
let { id: routeId } = useRemixRouteContext();
let { transitionManager } = useRemixEntryContext();
Expand Down Expand Up @@ -1211,32 +1206,6 @@ export function useFetchers(): Fetcher[] {
return [...fetchers.values()];
}

/**
* @deprecated replaced by `useTransition().submission`
*/
export function usePendingFormSubmit() {
let { transitionManager } = useRemixEntryContext();
let { submission } = transitionManager.getState().transition;
if (submission) {
return {
...submission,
data: submission.formData
};
}
}

/**
* Returns the next location if a location change is pending. This is useful
* for showing loading indicators during route transitions from `<Link>`
* clicks.
*
* @deprecated use `useTransition().location`
*/
export function usePendingLocation(): Location | undefined {
let { transitionManager } = useRemixEntryContext();
return transitionManager.getState().transition.location;
}

export function LiveReload({ port = 8002 }: { port?: number }) {
if (process.env.NODE_ENV !== "development") return null;
return (
Expand Down
6 changes: 1 addition & 5 deletions packages/remix-react/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ export {
useLoaderData,
useActionData,
useBeforeUnload,
useMatches,
// deprecated
usePendingLocation,
usePendingFormSubmit,
useRouteData
useMatches
} from "./components";

export type { FormMethod, FormEncType } from "./data";
Expand Down
6 changes: 1 addition & 5 deletions packages/remix-react/magicExports/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,5 @@ export {
useActionData,
useBeforeUnload,
useMatches,
RemixServer,
// @deprecated
usePendingLocation,
usePendingFormSubmit,
useRouteData
RemixServer
} from "@remix-run/react";