-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
feat: implement CodeInput component #1524
feat: implement CodeInput component #1524
Conversation
Features
Bug Fixes
Contributors@blakmetall, @LeandroTorresSicilia Commit-Lint commandsYou can trigger Commit-Lint actions by commenting on this PR:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that I should rethink your life cycle because it is very complex and makes you work harder. I think the first step should be to normalize "value" in an array and that array is core of your component. This is going to give you a few validations and checks now.
Try to get the functions out for the helpers and optimize using hook.
sure, thank you for your comments, applying all changes right away. |
…n comments from first revision * added useReduxForm hook inside the hooks export list * hooks list arranged alphabetically
Changes ready for a second revision... About the length prop you mentioned, it is used to establish the codeLength to be used for the component... This is the file with the props definitions I have https://docs.google.com/document/d/1PAFwTznCcUdz3_Vp9NJ5o0EFm3N4qcRY2GWQ1IXGl7Q/edit I changed the name from length to codeLength to be more explicit, if you think its best to be called different please let me know. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that the life cycle of this component should be this:
a variable values that is an array that is calculated based on the prop value and lenght, with that array you have the data to paint in complete component. assume this "1234" = [1, 2, 3, 4], "1 34" = [1, "", 3, 4], "12" = [1, 2, "", ""] = and " "= [" "," "," "," "] put this in a custom hook and use useMemo
a focusedIndex state that controls which input the focus is on
handleChange (newValue, index) converts the array to string and calls onChange
make a custom hook that has all the logic of keyPress
To optimize the repainting of nodes you can use a context where the fucusedIndex state and the handleChange are passed.
in the render you make a values.map for InputItem
the InputItem component is simple
props value, index and get from context fucusedIndex and handleChange
a useEffect to put focus
use keyDownPress to only enter numbers
and the onChange of the input calls handleChange (value, index)
I think you can delete the InputItems, all that logic can be in index.js
try to optimize everything you can using useMeme and useCallback.
…cus logic using states
thank you for all your comments, they totally changed the way I was seeing the component... |
} = props; | ||
|
||
const inputs = value.map((inputValue, index) => { | ||
const inputIndex = index; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const inputIndex = `code-input-${index}`;
|
||
return ( | ||
<StyledInput | ||
key={index} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove key={index}
fix: #1488
feat: implement codeInput component first revision