Skip to content
This repository was archived by the owner on Jan 7, 2020. It is now read-only.

Commit d071edc

Browse files
authored
Merge pull request #1 from runtastic/react-hooks
Rewrite component using hooks
2 parents 4daa1ff + 3c966e0 commit d071edc

File tree

8 files changed

+123
-10543
lines changed

8 files changed

+123
-10543
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
demo
22
umd
3+
lib

.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"parser": "babel-eslint",
33
"extends": "airbnb",
4+
"plugins": ["react-hooks"],
45
"rules": {
56
"max-len": [ 2, 140 ],
67
"eqeqeq": [ 2, "always", { "null": "never" }],
@@ -26,6 +27,8 @@
2627
"react/prop-types": 0,
2728
"react/jsx-no-bind": 0,
2829
"react/no-array-index-key": 0,
30+
"react-hooks/rules-of-hooks": "error",
31+
"react-hooks/exhaustive-deps": "warn",
2932
"comma-dangle": "off",
3033
"function-paren-newline": 0,
3134
"class-methods-use-this": 0

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ build/Release
2727
# Dependency directory
2828
node_modules
2929

30+
package-lock.json
31+
3032
# Optional npm cache directory
3133
.npm
3234

demo/demo.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import ReactDOM from 'react-dom';
33
import HexagonGrid from '../src/HexagonGrid';
44
import times from 'lodash/times';
55

6-
class HexGridDemo extends Component {
7-
getHexProps(hexagon) {
6+
const HexGridDemo = () => {
7+
const getHexProps = (hexagon) => {
88
return {
99
style: {
1010
fill: '#007aff',
@@ -14,7 +14,7 @@ class HexGridDemo extends Component {
1414
};
1515
}
1616

17-
renderHexagonContent(hexagon) {
17+
const renderHexagonContent = (hexagon) => {
1818
return (
1919
<text
2020
x="50%"
@@ -29,19 +29,17 @@ class HexGridDemo extends Component {
2929
);
3030
}
3131

32-
render () {
33-
let hexagons = times(102, id => id);
32+
let hexagons = times(102, id => id);
3433

35-
return (
36-
<HexagonGrid
37-
gridWidth={500}
38-
gridHeight={500}
39-
hexagons={hexagons}
40-
hexProps={this.getHexProps}
41-
renderHexagonContent={this.renderHexagonContent}
42-
/>
43-
);
44-
}
34+
return (
35+
<HexagonGrid
36+
gridWidth={500}
37+
gridHeight={500}
38+
hexagons={hexagons}
39+
hexProps={getHexProps}
40+
renderHexagonContent={renderHexagonContent}
41+
/>
42+
);
4543
}
4644

4745
ReactDOM.render(

demo/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<h1>react-hexagon-grid</h1>
1111
<div id="root"></div>
1212
</div>
13-
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react.min.js"></script>
14-
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-dom.min.js"></script>
13+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.8.5/umd/react.production.min.js"></script>
14+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.5/umd/react-dom.production.min.js"></script>
1515
<script src="bundle.js"></script>
1616
</body>
1717
</html>

0 commit comments

Comments
 (0)