Skip to content

Commit

Permalink
Improvements (#13)
Browse files Browse the repository at this point in the history
* Cleanup & Moved to yarn

* Added TSLint.
Added EditorConfig.
Added pre-commit hooks.
Fixed shadowed name "item".

* Removed babel config

* Updated EditorConfig

* Updated tslint configuration to support Prettier.

* Added prettier-tslint.

* Updated yarn lock

* Added prettier config

* Fixed linter issues with index.ts

* Removed unnecessary files from npm package

* Use React.Dispatch.

* Linted README

* Fixed GIF in README for NPM

* Fixed markdown linter
  • Loading branch information
TheAifam5 authored and dance2die committed Feb 11, 2019
1 parent 2788600 commit 1a71d5a
Show file tree
Hide file tree
Showing 14 changed files with 2,471 additions and 3,964 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dist/
temp
# Output directory
lib/

# Logs
logs
Expand Down
5 changes: 5 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"MD033": false,
"MD013": false,
"MD036": false
}
11 changes: 6 additions & 5 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
src
temp
.babelrc
.gitignore
react-use-localstorage.gif
/.*
/*.gif
/tsconfig.json
/tslint.json
/*.lock
/src
4 changes: 1 addition & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
tsconfig.json
temp/
src/
/lib
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"endOfLine": "lf"
}
59 changes: 35 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# react-use-localstorage

[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors)

_depends on stable v16.8.1~_
Expand All @@ -9,28 +10,27 @@ _depends on stable v16.8.1~_

Access [Local Storage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) using [React hooks](https://reactjs.org/docs/hooks-intro.html).

Fork it on CodeSandbox
Fork it on CodeSandbox
[![Edit usestate-useeffect](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/09xj95vxl)


# How to use it
## How to use it

```javascript
import React from "react";
import ReactDOM from "react-dom";
import useLocalStorage from "react-use-localstorage";
import React from 'react';
import ReactDOM from 'react-dom';
import useLocalStorage from 'react-use-localstorage';

import "./styles.css";
import './styles.css';

function App() {
const [item, setItem] = useLocalStorage("name", "Initial Value");
const [item, setItem] = useLocalStorage('name', 'Initial Value');

return (
<div className="App">
<h1>Set Name to store in Local Storage</h1>
<div>
<label>
Name:{" "}
Name:{' '}
<input
type="text"
placeholder="Enter your name"
Expand All @@ -43,51 +43,61 @@ function App() {
);
}

const rootElement = document.getElementById("root");
const rootElement = document.getElementById('root');
ReactDOM.render(<App />, rootElement);
```

# Demo
## Demo

![demo](react-use-localstorage.gif)
![demo](https://github.com/dance2die/react-use-localstorage/raw/master/react-use-localstorage.gif)

# Changelog
## Changelog

<details>
<summary><b>Expand Changelog</b></summary>

2.4.1

- Added `useLocalStorage` return type explicitly to generate correct `index.d.ts` typing file.

2.4.0
2.4.0

- Added TypeScript typings as suggested by @TheAifam5 in Issue #9

2.3.0
2.3.0

- Fixed a bug where initial value is returned all the time #7 by @lilasquared 🙏

2.2.0
2.2.0

- Sets initial value in local storage

2.1.0
2.1.0

- Can optionally pass an initial value
- This is to prevent form field from being uncontrolled.

2.0.0
2.0.0

- Breaking change - `setItem` doesn't require `key`

1.1.1
1.1.1

- Updated to React v16.8.1, which contains the patched Hooks

1.1.0
1.1.0

- Updated dev dependency version

1.0.0
1.0.0

- Updated to React v16.8.0, which contains the stable Hooks

0.0.6
0.0.6

- Changed the language from JavaScript to TypeScript
- It has minimized the distribution file greatly
</details>
</details>

## Contributors

Expand All @@ -97,6 +107,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/all-contri
<!-- prettier-ignore -->
| [<img src="https://avatars3.githubusercontent.com/u/3036779?v=4" width="100px;" alt="Aaron Roberts"/><br /><sub><b>Aaron Roberts</b></sub>](https://github.com/lilasquared)<br />[🤔](#ideas-lilasquared "Ideas, Planning, & Feedback") [🐛](https://github.com/dance2die/react-use-localstorage/issues?q=author%3Alilasquared "Bug reports") [💻](https://github.com/dance2die/react-use-localstorage/commits?author=lilasquared "Code") | [<img src="https://avatars1.githubusercontent.com/u/8465237?v=4" width="100px;" alt="Sung Kim"/><br /><sub><b>Sung Kim</b></sub>](https://twitter.com/dance2die)<br />[💻](https://github.com/dance2die/react-use-localstorage/commits?author=dance2die "Code") [🐛](https://github.com/dance2die/react-use-localstorage/issues?q=author%3Adance2die "Bug reports") [📖](https://github.com/dance2die/react-use-localstorage/commits?author=dance2die "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/2192274?v=4" width="100px;" alt="TheAifam5"/><br /><sub><b>TheAifam5</b></sub>](https://theaifam5.eu/)<br />[🤔](#ideas-TheAifam5 "Ideas, Planning, & Feedback") |
| :---: | :---: | :---: |

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
Loading

0 comments on commit 1a71d5a

Please sign in to comment.