-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
26 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
import { useCallback, useState } from "@rbxts/roact-hooked"; | ||
|
||
/** | ||
* Returns a function that can be used to force a component to update. | ||
* Returns a function that can be used to force a component to update. The | ||
* function is recreated on the next render if called. This makes it useful as | ||
* a dependency for other hooks. | ||
* @returns A function that forces a rerender. | ||
*/ | ||
export function useUpdate() { | ||
const [, setState] = useState({}); | ||
const [state, setState] = useState({}); | ||
|
||
return useCallback(() => { | ||
setState({}); | ||
}, []); | ||
}, [state]); | ||
} |