Skip to content

Commit 13fd4d0

Browse files
committedMay 12, 2020
first commit
0 parents  commit 13fd4d0

30 files changed

+15105
-0
lines changed
 

‎.babelrc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"node": "current"
8+
}
9+
}
10+
],
11+
"minify"
12+
],
13+
"plugins": ["@babel/plugin-proposal-class-properties"]
14+
}

‎.editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true

‎.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/node_modules

‎.eslintrc.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module.exports = {
2+
env: {
3+
jest: true,
4+
browser: true,
5+
es6: true,
6+
},
7+
parser: 'babel-eslint',
8+
extends: [
9+
'plugin:react/recommended',
10+
'airbnb',
11+
'prettier',
12+
'prettier/react'
13+
],
14+
globals: {
15+
Atomics: 'readonly',
16+
SharedArrayBuffer: 'readonly',
17+
},
18+
parserOptions: {
19+
ecmaVersion: 6,
20+
ecmaFeatures: {
21+
jsx: true,
22+
}
23+
},
24+
plugins: [
25+
'react',
26+
'prettier'
27+
],
28+
rules: {
29+
'prettier/prettier': 'error',
30+
'import/no-unresolved': 'off',
31+
'no-return-assign': 'off',
32+
},
33+
};

‎.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

‎.github/ISSUE_TEMPLATE/bug_report.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Screenshots**
24+
If applicable, add screenshots to help explain your problem.
25+
26+
**Desktop (please complete the following information):**
27+
- OS: [e.g. iOS]
28+
- Browser [e.g. chrome, safari]
29+
- Version [e.g. 22]
30+
31+
**Smartphone (please complete the following information):**
32+
- Device: [e.g. iPhone6]
33+
- OS: [e.g. iOS8.1]
34+
- Browser [e.g. stock browser, safari]
35+
- Version [e.g. 22]
36+
37+
**Additional context**
38+
Add any other context about the problem here.
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: helderburato
7+
---
8+
9+
**Is your feature request related to a problem? Please describe.**
10+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
11+
12+
**Describe the solution you'd like**
13+
A clear and concise description of what you want to happen.
14+
15+
**Describe alternatives you've considered**
16+
A clear and concise description of any alternative solutions or features you've considered.
17+
18+
**Additional context**
19+
Add any other context or screenshots about the feature request here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Description
2+
3+
You can provide a verbose description of what you've done or a step-by-step. Ex:
4+
5+
- Create JS for the given behavior

‎.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
*.log
3+
.DS_Store
4+
dist
5+
lib
6+
coverage
7+
package-lock.json

‎.huskyrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"hooks": {
3+
"pre-commit": "yarn lint"
4+
}
5+
}

‎.npmignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules
2+
.npmignore
3+
yarn.lock
4+
README.md
5+
.idea
6+
.babelrc
7+
LICENSE
8+
package.json
9+
examples

‎.prettierrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"tabWidth": 2,
3+
"singleQuote": true,
4+
"semi": true,
5+
"trailingComma": "all",
6+
"printWidth": 120
7+
}

‎CONTRIBUTING.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Contributing
2+
3+
1. Fork it!
4+
2. Create your feature branch: `git checkout -b my-new-feature`
5+
3. Commit your changes: `git commit -m 'Add some feature'`
6+
4. Push to the branch: `git push origin my-new-feature`
7+
8+
_Remember that we have a pre-push hook with steps that analyzes and prevents mistakes._
9+
10+
**After your pull request is merged**, you can safely delete your branch.

‎LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Helder Burato Berto - use-is-mounted-ref
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎README.md

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<div align="center">
2+
<h1>📦 use-is-mounted-ref</h1>
3+
4+
<p>📦 <strong>useIsMountedRef is a React Hook</strong> to check when the component is mounted.</p>
5+
</div>
6+
7+
---
8+
9+
## Motivation
10+
11+
- Avoid memory leaks setting states when component are unmounted;
12+
- Control when component already mounted;
13+
- Common error when setting state to unmounted component:
14+
15+
```js
16+
Warning: Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted component. This is a no-op.
17+
```
18+
19+
## Usage
20+
21+
To start using the `use-is-mounted-ref` in your project, first install in your project i.e:
22+
`yarn add use-is-mounted-ref` or `npm install use-is-mounted-ref`
23+
24+
<details open>
25+
<summary><strong>Avoid set state when unmounted component:</strong></summary>
26+
27+
```jsx
28+
import { useState, useEffect } from 'react';
29+
import useIsMounted from 'use-is-mounted-ref';
30+
31+
function App() {
32+
const isMounted = useIsMounted();
33+
34+
const initialState = {
35+
loading: false,
36+
error: false,
37+
data: [],
38+
};
39+
40+
const [state, setState] = useState(initialState);
41+
42+
useEffect(() => {
43+
fetch('https://www.reddit.com/.json')
44+
.then((response) => response.json())
45+
.then(({ data }) => {
46+
if (isMounted.current) {
47+
setState((prevState) => {
48+
return {
49+
...prevState,
50+
loading: false,
51+
data,
52+
};
53+
});
54+
}
55+
})
56+
.catch((err) => {
57+
if (isMounted.current) {
58+
setState((prevState) => {
59+
return { ...prevState, loading: false, error: true };
60+
});
61+
}
62+
});
63+
}, []);
64+
65+
return state.loading ? 'Loading...' : 'Found Data!';
66+
}
67+
68+
export default App;
69+
```
70+
71+
</details>
72+
73+
## Contributing
74+
75+
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
76+
77+
## Bugs and Sugestions
78+
79+
Report bugs or do suggestions using the [issues](https://github.com/helderburato/use-is-mounted-ref/issues).
80+
81+
## License
82+
83+
[MIT License](LICENSE) © [helderburato](https://helderburato.com)

‎examples/.gitignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

‎examples/README.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2+
3+
## Available Scripts
4+
5+
In the project directory, you can run:
6+
7+
### `yarn start`
8+
9+
Runs the app in the development mode.<br />
10+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11+
12+
The page will reload if you make edits.<br />
13+
You will also see any lint errors in the console.
14+
15+
### `yarn test`
16+
17+
Launches the test runner in the interactive watch mode.<br />
18+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19+
20+
### `yarn build`
21+
22+
Builds the app for production to the `build` folder.<br />
23+
It correctly bundles React in production mode and optimizes the build for the best performance.
24+
25+
The build is minified and the filenames include the hashes.<br />
26+
Your app is ready to be deployed!
27+
28+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29+
30+
### `yarn eject`
31+
32+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33+
34+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35+
36+
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37+
38+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39+
40+
## Learn More
41+
42+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43+
44+
To learn React, check out the [React documentation](https://reactjs.org/).
45+
46+
### Code Splitting
47+
48+
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
49+
50+
### Analyzing the Bundle Size
51+
52+
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
53+
54+
### Making a Progressive Web App
55+
56+
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
57+
58+
### Advanced Configuration
59+
60+
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
61+
62+
### Deployment
63+
64+
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
65+
66+
### `yarn build` fails to minify
67+
68+
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

0 commit comments

Comments
 (0)