Skip to content

Commit

Permalink
less bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Jul 3, 2022
1 parent 2e07578 commit d326ae3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
12 changes: 5 additions & 7 deletions hooks/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,11 @@ export function useErrorBoundary(cb) {
];
}

function hash(s) {
let h = 0,
i = s.length;
while (i > 0) {
h = ((h << 5) - h + s.charCodeAt(--i)) | 0;
}
return h;
function hash(str) {
let i = 0,
out = 11;
while (i < str.length) out = (101 * out + str.charCodeAt(i++)) >>> 0;
return out;
}

export function useId() {
Expand Down
8 changes: 4 additions & 4 deletions hooks/test/browser/useId.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ describe('useId', () => {

render(<Comp />, scratch);
expect(scratch.innerHTML).to.equal(
'<div id="P480"><div id="P15360"><span id="P15361">h</span></div></div>'
'<div id="P11590"><div id="P1171070"><span id="P1171071">h</span></div></div>'
);

render(<Comp />, scratch);
expect(scratch.innerHTML).to.equal(
'<div id="P480"><div id="P15360"><span id="P15361">h</span></div></div>'
'<div id="P11590"><div id="P1171070"><span id="P1171071">h</span></div></div>'
);
});

Expand All @@ -80,12 +80,12 @@ describe('useId', () => {

render(<Comp />, scratch);
expect(scratch.innerHTML).to.equal(
'<div id="P480"><span id="P15360">h</span><span id="P15670">h</span><span id="P15980">h</span></div>'
'<div id="P11590"><span id="P1171070">h</span><span id="P1171080">h</span><span id="P1171090">h</span></div>'
);

render(<Comp />, scratch);
expect(scratch.innerHTML).to.equal(
'<div id="P480"><span id="P15360">h</span><span id="P15670">h</span><span id="P15980">h</span></div>'
'<div id="P11590"><span id="P1171070">h</span><span id="P1171080">h</span><span id="P1171090">h</span></div>'
);
});
});

0 comments on commit d326ae3

Please sign in to comment.