useReducer dispatch flow clarification
Personne n'a encore pris cette issue.
- Langage dominant
- JavaScript
- Étoiles
- 11.8k
- Forks
- 7.9k
- Merge moyen
- 1 j 11 h
- PR mergées (30 j)
- 11
Description
Hi,
I've been looking around to try to find out more about the "dispatch / render" flow and can not find anything relevant yet.
My question is: when I do 2 dispatchsequentially such as:
dispatch({type: ACTION_1});
dispatch({type: ACTION_2});
Are we sure that the 2 actions will be processed before the next rendering cycle occurs?
Could it be that on the next rendering cycle, only ACTION_1 has been processed then ACTION_2 is processed on a later rendering cycle?
In other words, from the react perspective, is doing:
dispatch({type: ACTION_1});
dispatch({type: ACTION_2});
equivalent to:
dispatch({type: ACTIONS: payload: [ACTION_1, ACTION2]});
In a small demo, it seems that it doesn't matter:
https://codesandbox.io/s/tzp0s (see the console messages)
In my larger react app, it seems that often time there is a render cycle between 2 consecutive dispatch.
Is it considered an anti-pattern to do 2 dispatch sequentially and should we instead do 1 dispatch with the content of the 2 dispatch combined?
Thank you!
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Aucun fichier de documentation ni aucun test n’est nommé. Commencez par reproduire le comportement de dispatch séquentiel dans le CodeSandbox lié et comparez-le au comportement de l’application plus grande décrit ; le travail serait terminé une fois les directives React pertinentes localisées et la relation entre dispatch et rendu ainsi que l’utilisation recommandée clarifiées.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, react
- Domaine
- documentation, frontend
- Type d'issue
- Documentation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 35/100