-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify data entry forms #964
base: main
Are you sure you want to change the base?
Conversation
Sigrid maintainability feedbackShow detailsSigrid compared your code against the baseline of 2025-02-11. 👍 What went well?
👎 What could be better?
📚 Remaining technical debt
View this system in Sigrid** to explore your technical debt ⭐️ Sigrid ratings
💬 Did you find this feedback helpful?We would like to know your thoughts to make Sigrid better. |
Fixes #850
This PR is an overhaul of the state management for the data entry forms.
It introduces a "reducer" to centralize state manipulation and simplify the data flow using events.
Apart from the central form state, the local form hooks and components are cleaned up, in particular the number of hard-to-reason-about
useEffect
anduseRef
hooks are removed.See
frontend/app/component/form/data_entry/state
for the hooks, context and providers related to the data entry state.Notes:
main
ASAPuseReducer
Other notes on React state management:
The data flow we try to adhere to
In our case events are triggered from the UI, which are dispatched to the central reducer. The reducer updates the otherwise immutable state object. The React components render this immutable state as a UI.
Don't overuse
useRef
From the React documentation:
Don't overuse
useEffect
From the React documentation:
Strive for simple components with unidirectional data flow
useRef
useEffect
to preload API data, or trigger explicit side-effectsuseMemo
anduseCallback
hooks should only be used if they prevents expensive calculations - in Abacus this is almost never the case!