Triggering Refresh to Cookie in `useCookie`
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- typescript
- Área
- frontend
Línea de trabajo
Start at the existing useCookie hook and inspect how it reads and updates the cookie value. Compare its current return value and update behavior with the requested refresh operation. Done means an external cookie change can be read through the hook after refresh is called, with deletion still reflected in the hook state.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Is your feature request related to a problem? Please describe.
My cookie is changed by a request done in some API call. I need to react to that change. The new cookie value is not by useCookie() because it assumes that all changes are done through it.
Describe the solution you'd like
A refresh would probably suffice. Something like this:
import { useCallback, useState } from 'react';
import Cookies from 'js-cookie';
const useCookie = (
cookieName: string
): [string | null, (newValue: string, options?: Cookies.CookieAttributes) => void, () => void, () => void] => {
const [value, setValue] = useState<string | null>(() => Cookies.get(cookieName) || null);
const updateCookie = useCallback(
(newValue: string, options?: Cookies.CookieAttributes) => {
Cookies.set(cookieName, newValue, options);
setValue(newValue);
},
[cookieName]
);
const refreshCookie = useCallback(() => {
const newValue = Cookies.get(cookieName);
if (newValue === value) {
return;
}
if (newValue !== undefined) {
updateCookie(newValue);
} else {
deleteCookie();
}
}, [cookieName, updateCookie, value]);
const deleteCookie = useCallback(() => {
Cookies.remove(cookieName);
setValue(null);
}, [cookieName]);
return [value, updateCookie, deleteCookie, refreshCookie];
};
export default useCookie;
(not tested)
Usage:
const [value, update, delete, refresh] = useCookie("sessionData");
// ...
fetch("/settings/update").then(() => refresh());
Describe alternatives you've considered
I'm open for suggestions
- Lenguaje dominante
- TypeScript
- Estrellas
- 44k
- Forks
- 3.3k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de streamich/react-use
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Add Generic Fn for useDebouncePosiblemente ocupada @itsmejay80 la tomó hace 187 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
-
useVideo.story.tsx - sampleVideo can not be loadedQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 62/100
-
useSlider: event callbacks are not updatedPosiblemente ocupada @erykpiast la tomó hace 1834 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Todos los issues de streamich/react-use
Issues similares
-
documentation good first issue
Dificultad 2/5 Medio día Aptitud para principiantes 72/100
sujithputta02/Esapay#13 ·
-
Share dialog: the address book's contact count reads "1 contacts" (no singular form in any language)Posiblemente ocupada @chibenwa la tomó hoy. Abiertoai-driven-qa bug claude Cosmetic
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
linagora/twake-contacts-frontend#271 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Koenkk/zigbee2mqtt#33402 ·
Los mantenedores suelen responder en 1 día
-
dx P2 platform Stellar Wave Wave 10
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
winsznx/routedock#579 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
area:ui effort:S enhancement priority:P2
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día