Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

state management and architecture decision #30

Merged
merged 17 commits into from
Mar 29, 2023

Conversation

buenaflor
Copy link
Contributor

No description provided.

@buenaflor buenaflor requested a review from markus2330 January 19, 2023 18:46
Copy link
Contributor

@markus2330 markus2330 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to agree with the decisions but some explanations etc. is missing.

doc/decisions/frontend_architecture_pattern.md Outdated Show resolved Hide resolved
doc/decisions/frontend_architecture_pattern.md Outdated Show resolved Hide resolved
doc/decisions/frontend_architecture_pattern.md Outdated Show resolved Hide resolved
doc/decisions/frontend_architecture_pattern.md Outdated Show resolved Hide resolved
doc/decisions/frontend_state_management.md Show resolved Hide resolved
doc/decisions/frontend_state_management.md Outdated Show resolved Hide resolved
doc/decisions/frontend_state_management.md Outdated Show resolved Hide resolved
@markus2330
Copy link
Contributor

Ideally you already add to doc/architecture the main choices&differences to Bulletproof React, otherwise it is only a half decision.

@markus2330 markus2330 mentioned this pull request Mar 10, 2023
27 tasks
@absurd-turtle absurd-turtle force-pushed the decision/frontend_architecture_pattern branch from 5b6e3e0 to 66790df Compare March 16, 2023 17:18
@Bushuo
Copy link
Contributor

Bushuo commented Mar 19, 2023

Hi, I heard great things about Zustand but never used it myself. I usually just went with Apollo Client as I mostly developed my personal React applications with a GraphQL backend.

But I would like to point out, that I would not use Zustand in the way it is currently used inside the seeds feature.
React Query is a better tool for handling server state.

Just a quick pointer about state.
We can usually distinguish between three types of state inside a React application.

  1. Local Component State -> is the dropdown open or not, is the checkbox clicked or not, and so on.
    I would use the default react useState for this or Context + useReducer for more complex local state

  2. Application State -> Synchronous State. Local user preferences, UI state in a visual desgin app
    This is where 'Zustand' should be used

  3. Server State -> Async state. A network request is needed before any state can be derived.
    I would use 'React Query' for this.

My rationale for this is, React Query has integrated mechanisms for network error states, deduping, retries, optimistic ui and so on. Thus much of the wiring code that would be needed in the local state management approach is just included.

Here is the documentation that points out the differences to local state management tools
https://react-query-v3.tanstack.com/guides/does-this-replace-client-state
And a quick 100 second summary of React Query
https://www.youtube.com/watch?v=novnyCaa7To
A blog post of the official maintainer, he is also based in Vienna 🎉
https://tkdodo.eu/blog/practical-react-query
Official Docu, I think they renamed it to tanstack/query for version 4
https://tanstack.com/query/latest/docs/react/overview

Edit: added useful links

@buenaflor
Copy link
Contributor Author

@Bushuo Yup, makes sense and I agree with this.

@markus2330
Copy link
Contributor

We can usually distinguish between three types of state inside a React application.

Please write this in the beginning of the decision to clarify the context what gets decided.

Edit: added useful links

Please also add then to either #43 or the decision (if they are specific to understand the decision and not really relevant to get started with PermaplanT).

@absurd-turtle absurd-turtle force-pushed the decision/frontend_architecture_pattern branch 2 times, most recently from 9c0dc45 to 915f063 Compare March 21, 2023 10:58
@absurd-turtle
Copy link
Contributor

absurd-turtle commented Mar 21, 2023

@Bushuo

Yes, it makes perfect sense to distinguish between the "types" of state.
I separated the concerns in the decision document.
Do you have any insights on why to use React Query specifically as opposed to vercel/swr for example?

@Bushuo
Copy link
Contributor

Bushuo commented Mar 21, 2023

@Bushuo

Yes, it makes perfect sense to distinguish between the "types" of state. I separated the concerns in the decision document. Do you have any insights on why to use React Query specifically as opposed to vercel/swr for example?

@absurd-turtle Yup, swr is more minimalistic for easy use cases. React Query also has for example, builtin features for pagination. I think in our case a more holistic solution should be preferred.

@absurd-turtle absurd-turtle requested a review from Bushuo March 21, 2023 15:57
@absurd-turtle absurd-turtle force-pushed the decision/frontend_architecture_pattern branch from a57f234 to d270848 Compare March 21, 2023 17:35
doc/decisions/frontend_architecture_pattern.md Outdated Show resolved Hide resolved
@markus2330
Copy link
Contributor

@Bushuo please also add all the details you know about the different state libs. Feel free to push here.

@Bushuo
Copy link
Contributor

Bushuo commented Mar 23, 2023

Hi @markus2330

Please also add all the details you know about the different state libs. Feel free to push here.

The ones I know of are either already included (Redux), or related to GraphQL.
I think the decision is ready to be merged.

Copy link
Contributor

@markus2330 markus2330 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, good that we looked into this again!

doc/decisions/frontend_architecture_pattern.md Outdated Show resolved Hide resolved
doc/decisions/frontend_architecture_pattern.md Outdated Show resolved Hide resolved
@markus2330 markus2330 merged commit c124088 into master Mar 29, 2023
@markus2330 markus2330 deleted the decision/frontend_architecture_pattern branch March 29, 2023 12:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants