-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(testHook): modify testHook to return unmount function (#290)
* Returns unmount function on testHook * Adds test for unmount function; Adds example of useEffect * Add Andrewmat as contributor * Adds rerender on testHook return
- Loading branch information
Showing
8 changed files
with
164 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,25 @@ | ||
import {useState} from 'react' | ||
import {useState, useEffect} from 'react' | ||
|
||
function useCounter({initialCount = 0, step = 1} = {}) { | ||
export function useCounter({initialCount = 0, step = 1} = {}) { | ||
const [count, setCount] = useState(initialCount) | ||
const increment = () => setCount(c => c + step) | ||
const decrement = () => setCount(c => c - step) | ||
return {count, increment, decrement} | ||
} | ||
|
||
export default useCounter | ||
export function useDocumentTitle(title) { | ||
const [originalTitle, setOriginalTitle] = useState(document.title) | ||
useEffect(() => { | ||
setOriginalTitle(document.title) | ||
document.title = title | ||
return () => { | ||
document.title = originalTitle | ||
} | ||
}, [title]) | ||
} | ||
|
||
export function useCall(callback, deps) { | ||
useEffect(() => { | ||
callback() | ||
}, deps) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters