Brandon Presley
6950cd04f4
The App.tsx had a bunch of separate useState calls which would cause unneccesary re-renders of the entire app. This became apparent after adding the global progress bar, since it caused even more re-renders to the point of being unusable.
34 lines
765 B
TypeScript
34 lines
765 B
TypeScript
import React, { useEffect, useState } from "react";
|
|
import { Snackbar } from "react-native-paper";
|
|
import { emitter } from "./emitter";
|
|
import { TOAST } from "./toast";
|
|
|
|
export default function AppSnack({ textColor }: { textColor: string }) {
|
|
const [snackbar, setSnackbar] = useState("");
|
|
|
|
useEffect(() => {
|
|
const description = emitter.addListener(
|
|
TOAST,
|
|
({ value }: { value: string }) => {
|
|
setSnackbar(value);
|
|
}
|
|
);
|
|
return description.remove;
|
|
}, []);
|
|
|
|
return (
|
|
<Snackbar
|
|
duration={3000}
|
|
onDismiss={() => setSnackbar("")}
|
|
visible={!!snackbar}
|
|
action={{
|
|
label: "Close",
|
|
onPress: () => setSnackbar(""),
|
|
textColor,
|
|
}}
|
|
>
|
|
{snackbar}
|
|
</Snackbar>
|
|
);
|
|
}
|