Skip to content

Commit

Permalink
update readme with more option specifics
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerwolff committed Apr 3, 2022
1 parent ff39d41 commit 698c998
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,26 @@ export default props => {
};
```

`setUserToken` accepts a second argument: `options`. Different to the named
export, for this one it is the second not the third argument. Take a look at
[setCookie](#setcookie) for more details.
In this example you can also set custom cookie options by passing an options object to `setUserToken`:

```js
setUserToken('abcd', {
days: 365,
samesite: 'strict',
secure: true,
});
```

See [setCookie](#setcookie) for more option information about this.

This package also has a few other exports that can be used directly.
As a convenience this package also exports the get and set functions so they can be used directly.

### `getCookie`

If you need to access a cookie outside of a React component, you can use the
named `getCookie` export:
exported `getCookie` function:

```jsx
```js
import { getCookie } from 'react-use-cookie';

const getUser = () => {
Expand All @@ -58,24 +66,35 @@ const getUser = () => {
### `setCookie`

If you need to set a cookie outside of a React component, you can use the
named `setCookie` export:
exported `setCookie` function:

```jsx
```js
import { setCookie } from 'react-use-cookie';

const saveLocale = locale => {
setCookie('locale', locale);
setCookie('locale', locale, {
days: 1,
domain: 'github.com',
samesite: 'lax',
secure: true,
});
};
```

You can also specify an optional third argument - the same options object as
above:
You can also specify cookie options as a third argument:

```tsx
{
// The number of days the cookie is stored (defaults to 7)
days: number;
days?: number;

// The path of the cookie (defaults to '/')
path: string;
path?: string;

// No defaults
domain?: string;
samesite?: 'none' | 'lax' | 'strict';
secure?: boolean;
}
```

Expand Down

0 comments on commit 698c998

Please sign in to comment.