我想运行一个函数,并在我的输入值中传递一些参数,但它给了我这个错误:Invalid value for prop
值on <input> tag. Either remove it from the element, or pass a string or number value to keep it in the DOM.
我记得阅读读过一篇文章,说你可以在value
中使用函数,但这对我不起作用。有没有别的方法?
value={() => this.handleMapping(row.servername, "Data Source Server")}
字符串
错误:Invalid value for prop
值on <input> tag. Either remove it from the element, or pass a string or number value to keep it in the DOM.
3条答案
按热度按时间hvvq6cgz1#
你在这里提供了一个匿名函数,
字符串
相反,您只需要提供函数,该函数将在组件加载时执行。
型
另外,确保
handleMapping
函数应该返回一些可以被视为输入值的东西。Simplified Demo
**注意:**还请确保在输入时提供
onChange
处理程序。6ovsh4lw2#
你不能执行/运行函数,因为你需要一些事件来执行它,但是你只能在返回一些整数或字符串的情况下使用值函数。
aelbi1ox3#
试试这个:
字符串
这将运行匿名函数