Skip to content

Commit

Permalink
fix: preserve value when re-rendering
Browse files Browse the repository at this point in the history
Refs: #97
  • Loading branch information
jgillick authored Jan 18, 2025
1 parent 9255d15 commit 89732a0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/pin-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const PinField = forwardRef<HTMLInputElement[], Props>(

function handleKeyDownAt(index: number): KeyboardEventHandler<HTMLInputElement> {
return event => {
console.log("keyDown", index, event);
const { key, code, keyCode, which } = event;
dispatch({ type: "handle-key-down", index, key, code, keyCode, which });
};
Expand Down Expand Up @@ -144,6 +143,7 @@ export const PinField = forwardRef<HTMLInputElement[], Props>(
{...nativeProps}
key={index}
ref={setRefAt(index)}
value={index in state.values ? state.values[index] : ""}
autoFocus={index === 0 && autoFocus}
onKeyDown={handleKeyDownAt(index)}
onChange={handleChangeAt(index)}
Expand Down

0 comments on commit 89732a0

Please sign in to comment.