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

Commit

Permalink
fix: Fix bug where an initialInstanceState of type function always ge…
Browse files Browse the repository at this point in the history
…ts called every render

closes #1
  • Loading branch information
jack-allan-fenergo committed Dec 23, 2018
1 parent b7efe52 commit 95a1bc6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useState, useMemo } from "react";

export default function useInstance(initialInstanceState) {
const [{ instance }, updateInstance] = useState({
const [{ instance }, updateInstance] = useState(() => ({
instance:
typeof initialInstanceState === "function"
? initialInstanceState()
: initialInstanceState
});
}));
return useMemo(() => [
instance,
function update() {
Expand Down

0 comments on commit 95a1bc6

Please sign in to comment.