Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 输入失去焦点,每个按键笔划-文本字段反应格式编号_Reactjs_React Number Format - Fatal编程技术网

Reactjs 输入失去焦点,每个按键笔划-文本字段反应格式编号

Reactjs 输入失去焦点,每个按键笔划-文本字段反应格式编号,reactjs,react-number-format,Reactjs,React Number Format,我已经使用react number格式创建了一个输入组件(InputComponent)。此组件仅接受带一个小数点的字符串数值。示例:“12.5”或“12”,但不是“12.55”。 这很有效 但是当我使用InputComponent构建另一个组件(BiggerComponent)时,输入会在每个按键上失去焦点 我刚刚解决了这个问题,将使用NumberFormat的函数移到输入函数之外。 我认为,如果它在输入函数中,则整个NumberFormat函数将在每个按键笔划时重新创建。这就是它失去焦点的原

我已经使用
react number格式创建了一个输入组件(
InputComponent
)。此组件仅接受带一个小数点的字符串数值。示例:
“12.5”
“12”
,但不是
“12.55”
。 这很有效

但是当我使用
InputComponent
构建另一个组件(
BiggerComponent
)时,输入会在每个按键上失去焦点


我刚刚解决了这个问题,将使用
NumberFormat
的函数移到输入函数之外。 我认为,如果它在
输入
函数中,则整个
NumberFormat
函数将在每个按键笔划时重新创建。这就是它失去焦点的原因

工作示例:(在输入函数中使用NumberFormat的函数)

工作示例:(在输入函数外部使用NumberFormat的函数)