perf(OTP): useState initializer function called only once (#52878)

Co-authored-by: thinkasany <480968828@qq.com>
This commit is contained in:
Herb 2025-02-19 14:52:54 +08:00 committed by GitHub
parent 9b854e43dc
commit 444f579eb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -153,7 +153,7 @@ const OTP = React.forwardRef<OTPRef, OTPProps>((props, ref) => {
const internalFormatter = (txt: string) => (formatter ? formatter(txt) : txt);
// ======================== Values ========================
const [valueCells, setValueCells] = React.useState<string[]>(
const [valueCells, setValueCells] = React.useState<string[]>(() =>
strToArr(internalFormatter(defaultValue || '')),
);