mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-09 14:43:03 -04:00
Add useEffect/useState/useMemo to webpack commons
This commit is contained in:
parent
989bd36eeb
commit
94ad8e8f61
4 changed files with 21 additions and 13 deletions
|
@ -16,7 +16,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Clipboard, React, Toasts } from "@webpack/common";
|
||||
import { Clipboard, React, Toasts, useEffect, useState } from "@webpack/common";
|
||||
|
||||
/**
|
||||
* Makes a lazy function. On first call, the value is computed.
|
||||
|
@ -48,13 +48,13 @@ export function useAwaiter<T>(factory: () => Promise<T>, providedOpts?: AwaiterO
|
|||
deps: [],
|
||||
onError: null,
|
||||
}, providedOpts);
|
||||
const [state, setState] = React.useState({
|
||||
const [state, setState] = useState({
|
||||
value: opts.fallbackValue,
|
||||
error: null,
|
||||
pending: true
|
||||
});
|
||||
|
||||
React.useEffect(() => {
|
||||
useEffect(() => {
|
||||
let isAlive = true;
|
||||
if (!state.pending) setState({ ...state, pending: true });
|
||||
|
||||
|
@ -72,7 +72,7 @@ export function useAwaiter<T>(factory: () => Promise<T>, providedOpts?: AwaiterO
|
|||
* Returns a function that can be used to force rerender react components
|
||||
*/
|
||||
export function useForceUpdater() {
|
||||
const [, set] = React.useState(0);
|
||||
const [, set] = useState(0);
|
||||
return () => set(s => s + 1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue