Skip to content
This repository was archived by the owner on Jun 6, 2019. It is now read-only.

Commit 95a1bc6

Browse files
fix: Fix bug where an initialInstanceState of type function always gets called every render
closes #1
1 parent b7efe52 commit 95a1bc6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useState, useMemo } from "react";
22

33
export default function useInstance(initialInstanceState) {
4-
const [{ instance }, updateInstance] = useState({
4+
const [{ instance }, updateInstance] = useState(() => ({
55
instance:
66
typeof initialInstanceState === "function"
77
? initialInstanceState()
88
: initialInstanceState
9-
});
9+
}));
1010
return useMemo(() => [
1111
instance,
1212
function update() {

0 commit comments

Comments
 (0)