Feature/checkbox form#2
Conversation
…ent feature to update default value after click next/back button, show answer in Confirm Panel
…aultOption for cases like Input Radio
|
General question did you intentionally avoided a redux pattern (action->reducer->store) ? |
| ...formState | ||
| }; | ||
|
|
||
| for (let key in updateFormPage) { |
There was a problem hiding this comment.
errrm ... should not for..in in general imho
There was a problem hiding this comment.
sure, I am trying to keep it simple, which means I have only Parent Business Login and trying to propagate the methods to the Functional Component
There was a problem hiding this comment.
updateFormPage is object not array
There was a problem hiding this comment.
I think Object.entries would be your better choice here
There was a problem hiding this comment.
I can replace for ... in with Object.entries()
| }; | ||
|
|
||
| for (let key in updateFormPage) { | ||
| if ('text' !== updateFormPage[key]['elementConfig']['type']) { |
There was a problem hiding this comment.
this looks structurally intimidating at first glance ...
react-quiz/src/components/Form/Form.js
Lines 42 to 51 in c3ca710
can you try to write the code that the reader is able to understand what it does without parsing each line ?
| }; | ||
| updatedFormElement.value = event.target.value; | ||
|
|
||
| if ('radio' === updatedFormElement.elementConfig.type) { |
There was a problem hiding this comment.
also this is one more "wtf" block - more readybility in terms of getting WHAT / WHAT-FOR it does - this way I can read it line by line in terms of HOW
react-quiz/src/components/Form/Form.js
Lines 70 to 84 in c3ca710
There was a problem hiding this comment.
I can extract and put into a arrow function to be more readable
There was a problem hiding this comment.
yes adopting clean-code principals and moving logic into named functional scopes will help a lot here :)
| const panelType = quizForm[formState.step].typePanel || ''; | ||
| let panelType = quizForm[formState.step].typePanel || ''; | ||
|
|
||
| const calcAnswersTOTAL = updatedForm => { |
There was a problem hiding this comment.
I would try to get this information from the store, as you already have to update the state per answered question, it would be easy to have the value stored there
There was a problem hiding this comment.
I found it, from performance point of view to have a function to calculate all the answered questions and I called once.
Form.js is a Functional Component and is does not have proper State
There was a problem hiding this comment.
In general "performance-reasons" or rather performance optimizations should be tackled when measurable / testable issues are discovered in an early version - as long as there is no issue I would always follow the best approach for maintainability and or readability.
| let primaryMessage = 'Game Over'; | ||
| const points = calcAnswersTOTAL(quizForm); | ||
|
|
||
| if (points >= 6) { |
There was a problem hiding this comment.
I'd say avoid magic numbers - read it from a config / named-constant
| onChange={props.changed} | ||
| /> | ||
| ); | ||
| if ('radio' === props.elementConfig.type) { |
There was a problem hiding this comment.
general pattern of special/specific code in generalized component does not feel right:
react-quiz/src/components/UI/Input/Input.js
Lines 9 to 39 in c3ca710
No description provided.