Skip to content

Commit

Permalink
Merge pull request #44 from bb7hn/dev
Browse files Browse the repository at this point in the history
Dev To Main
  • Loading branch information
bb7hn committed Sep 3, 2023
2 parents e6de851 + b6c43f9 commit 9a896a8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 33 deletions.
45 changes: 15 additions & 30 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This package contains predefined ready to use custom `React hooks`

[![npm version](https://badge.fury.io/js/r-custom-hooks.svg)](https://www.npmjs.com/package/r-custom-hooks) ![license](https://img.shields.io/github/license/bb7hn/react-custom-hooks.svg) [![coverage](https://codecov.io/github/bb7hn/react-custom-hooks/graph/badge.svg?token=MQMFW6N80S)](https://codecov.io/github/bb7hn/react-custom-hooks)

![publish workflow](https://github.com/bb7hn/react-custom-hooks/actions/workflows/npm-publish.yml/badge.svg)
![NPM CI](https://github.com/bb7hn/react-custom-hooks/actions/workflows/npm-publish.yml/badge.svg)
[![Known Vulnerabilities](https://snyk.io/test/github/bb7hn/react-custom-hooks/badge.svg)](https://snyk.io/test/github/bb7hn/react-custom-hooks)

![Eslint](https://img.shields.io/badge/eslint-3A33D1?style=for-the-badge&logo=eslint&logoColor=white)![VsCode](https://img.shields.io/badge/Visual_Studio_Code-0078D4?style=for-the-badge&logo=visual%20studio%20code&logoColor=white)
Expand All @@ -19,43 +19,28 @@ npm install r-custom-hooks
yarn add r-custom-hooks
```

## HOOKS
## HOOKS & Usage Examples

<details>
<summary><b><i>useCookie</i></b></summary>
<p>This hook is for managing cookies in your application.</p>

```ts
import React from 'react';
import {useCookie} from 'r-custom-hooks';

function MyComponent() {
// Use the useCookie hook to get, update, and delete cookies
const [username, setUsername, deleteUsername] = useCookie('username', 'Guest', 7);

const handleUpdateUsername = () => {
const newUsername = prompt('Enter your username:');
if (newUsername) {
setUsername(newUsername, 7); // Set the username with a 7-day expiration
}
};

const handleDeleteUsername = () => {
deleteUsername(); // Delete the username cookie
};

return (
<div>
<p>Welcome, {username}!</p>
<button onClick={handleUpdateUsername}>Update Username</button>
<button onClick={handleDeleteUsername}>Delete Username</button>
</div>
);
import {useCookie} from "r-custom-hooks"

export default function CookieComponent() {
const [cookie, updateCookie, removeCookie] = useCookie("name", "John Doe")

return (
<>
<div>{cookie}</div>
<button onClick={() => updateCookie("Jane Doe")}>Change Name To Jane Doe</button>
<button onClick={removeCookie}>Delete Name</button>
</>
)
}

export default MyComponent;

```

</details>

<details>
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "r-custom-hooks",
"version": "0.1.19",
"version": "0.1.20",
"description": "Predefined custom react hooks",
"files": [
"dist/**"
Expand Down

0 comments on commit 9a896a8

Please sign in to comment.