evelynhathaway / use-back

πŸ‘ˆβœ¨ React Router DOM hook for navigating back without leaving your website

Home Page:https://npmjs.com/package/use-back

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use Back icon

Use Back

React Router DOM hook for navigating back without leaving your website

npm version check status license: MIT

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

npm install use-back

Note: This package is a native ESModule that requires React Router DOM v6 as a peer dependency.

Usage

import {useBack} from "use-back";

const BackButton = () => {
	const {hasBack, handleBack} = useBack();
	return (
		<button type="button" onClick={handleBack}>
			{hasBack ? "Go Back" : "Go Home"}
		</button>
	);
};

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

About

πŸ‘ˆβœ¨ React Router DOM hook for navigating back without leaving your website

https://npmjs.com/package/use-back

License:MIT License


Languages

Language:TypeScript 66.4%Language:JavaScript 29.7%Language:Shell 3.9%