Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/evelynhathaway/use-back
👈✨ React Router DOM hook for navigating back without leaving your website
https://github.com/evelynhathaway/use-back
esmodules history hooks react react-router
Last synced: 2 months ago
JSON representation
👈✨ React Router DOM hook for navigating back without leaving your website
- Host: GitHub
- URL: https://github.com/evelynhathaway/use-back
- Owner: evelynhathaway
- License: mit
- Created: 2021-05-20T02:36:34.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-21T18:44:54.000Z (over 2 years ago)
- Last Synced: 2024-10-01T16:09:23.567Z (3 months ago)
- Topics: esmodules, history, hooks, react, react-router
- Language: TypeScript
- Homepage: https://npmjs.com/package/use-back
- Size: 399 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Use Back
**React Router DOM hook for navigating back without leaving your website**
[![npm version](https://badgen.net/npm/v/use-back?icon=npm)](https://www.npmjs.com/package/use-back)
[![check status](https://badgen.net/github/checks/evelynhathaway/use-back/main?icon=github)](https://github.com/evelynhathaway/use-back/actions)
[![license: MIT](https://badgen.net/badge/license/MIT/blue)](/LICENSE)## Description
A native ESModule React hook for navigating back one location using React Router DOM, defaulting to navigating home instead of leaving your web application.
## Installation
```bash
npm install use-back
```**Note:** This package is a native ESModule that requires React Router DOM v6 as a peer dependency.
## Usage
```tsx
import {useBack} from "use-back";const BackButton = () => {
const {hasBack, handleBack} = useBack();
return (
{hasBack ? "Go Back" : "Go Home"}
);
};
```### `useBack([defaultPath])`
**Returns**: `{handleBack, hasBack}` Object containing an event handler that navigates back, and a boolean that indicates whether the handler will navigate back or to the default path
| Parameter | Type | Default | Description |
| ----------- | -------- | ------- | --------------------------------------------------------------------------- |
| defaultPath | `string` | `"/"` | Fallback path to navigate to for when there is not a previous history entry |## License
Copyright Evelyn Hathaway, [MIT License](/LICENSE)