Mejora de la gestión del estado: Evitar la mutación direct#5
Merged
JMLTUnderCode merged 5 commits intomainfrom Sep 24, 2025
Merged
Mejora de la gestión del estado: Evitar la mutación direct#5JMLTUnderCode merged 5 commits intomainfrom
JMLTUnderCode merged 5 commits intomainfrom
Conversation
…nes a usar el hook useCallBack para memorizar las funciones
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors global state management in the Clontube frontend by eliminating direct state mutations and ensuring all state updates are performed through dispatch functions. The changes enforce proper React state management patterns and improve the predictability of state changes.
- Introduces new type definitions for
LoginandRegisterto improve type safety - Adds dedicated action types and handlers for setting login and register fields separately
- Replaces direct state mutations with proper dispatch calls in form components
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/types.ts | Adds new type definitions and updates action types to support separate field management |
| src/reducers/loginView.ts | Adds new action handlers for SET_LOGIN_FIELDS and SET_REGISTER_FIELDS |
| src/providers/LoginViewProvider.tsx | Introduces memoized dispatch functions for field updates and removes parameter-based state changes |
| src/components/FormRegister.tsx | Replaces direct state mutation with setRegisterFields dispatch call |
| src/components/FormLogin.tsx | Replaces direct state mutation with setLoginFields dispatch call |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Eliminacion de espacios Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Eliminacion de espacios Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request: Mejora de la gestión del estado: evite la mutación directa, utilice el patrón de envío.
Resumen
Este PR refactoriza la gestión de estado global en el frontend de Clontube, eliminando la mutación directa del estado React y asegurando que todas las actualizaciones de estado se realicen mediante dispatch. Este PR soluciona el issue #4
Cambios principales
Eliminación de mutaciones directas:
Se reemplazó cualquier asignación directa sobre objetos de estado (por ejemplo,
LOGIN_VIEW_STATE.loginFields.identifier = value) por llamadas a funciones de dispatch (comosetLoginFields,setRegisterFields).Uso consistente de dispatch:
Todas las actualizaciones de estado global ahora pasan por funciones de dispatch, asegurando que React detecte los cambios y re-renderice correctamente los componentes afectados.
Memorización de funciones de actualización:
Las funciones como
setLoginFieldsysetRegisterFieldsestán memorizadas usandouseCallbacken el provider, permitiendo su uso seguro en dependencias de hooks comouseEffect.Corrección de dependencias en hooks:
Se ajustaron los arrays de dependencias en los
useEffectpara evitar warnings de ESLint y prevenir bugs de renderizado.Mejoras en la estructura del contexto:
El contexto y el provider ahora exponen solo funciones y estados necesarios, siguiendo el principio de encapsulamiento.
Beneficios
Archivos principales modificados
src/providers/LoginViewProvider.tsxsrc/reducers/loginView.tsFormLogin,FormRegister, etc.)Notas