Closed devjoseluis closed 2 years ago
This may be linked to #44. The problem comes from the web component: React props are not sync with it. I will investigate. Thanks!
The native web component was a big mistake, it led to so many issues… I ended up rolling back to v1
state, without web component (pure React implementation). The issue should be fixed starting from the v3.0.11
.
Description
React local state values don't get updated on the
onChange
event callback prop of theReactPinField
component.Expected Behavior
The local state should be in sync when executing the
onChange
function.Actual Behavior
The local state value isn't in sync when executing the
onChange
function.Possible Fix
It is possible that mutating the original props object may cause this issue. https://github.com/soywod/react-pin-field/blob/133b5a5ed4de523f9572117229e80989eed65aa4/src/index.ts#L30
Steps to Reproduce
const [myState, setMyState] = useState("initialValue");
).ReactPinField
onChange
event. (ex.onChange={myHandlerFunction}
).console.log(myState);
).onChange
event callback is triggered, the initial state value is logged in the console.onChange
callback again; the console shows the initial state value instead of the updated value.Environment