react-dom.development.js:86 Warning: Expected `onChange` listener to be a function, instead got a value of `object` type.
时间: 2024-05-06 22:21:37 浏览: 200
这个问题通常表示你在给一个表单元素绑定 onChange 事件时,传入的不是一个函数,而是一个对象。你可以检查一下代码,看看是不是在给表单元素绑定时出了错,或者是引入的组件出了问题。建议可以检查一下代码中是否有类似下面的错误,然后进行修复:
```
<input
type="text"
value={this.state.inputValue}
onChange={{this.props.handleInputChange}}
/>
```
应该修改为:
```
<input
type="text"
value={this.state.inputValue}
onChange={this.props.handleInputChange}
/>
```
相关问题
{ type: "searchSelect", placeholder: "签约机构", valueName: 'signOrganId', optionName: "label", searchItemName: "label", optionId: "key", searchApi:commonService.orgPageList({}).then(res=>{ const {retData}=res retData.map(item=>{ return {key: item.id, label: item.organName, value: item.id,} }) }) }, 分析一下此段代码的报错 汉语解释index.jsx:55 Uncaught TypeError: item.searchApi is not a function at searchQuery (index.jsx:55:1) at onFocus (index.jsx:129:1) at onContainerFocus (BaseSelect.js:326:1) at HTMLUnknownElement.callCallback (react-dom.development.js:188:1) at Object.invokeGuardedCallbackDev (react-dom.development.js:237:1) at invokeGuardedCallback (react-dom.development.js:292:1) at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:306:1) at executeDispatch (react-dom.development.js:389:1) at executeDispatchesInOrder (react-dom.development.js:414:1) at executeDispatchesAndRelease (react-dom.development.js:3278:1) at executeDispatchesAndReleaseTopLevel (react-dom.development.js:3287:1) at forEachAccumulated (react-dom.development.js:3259:1) at runEventsInBatch (react-dom.development.js:3304:1) at runExtractedPluginEventsInBatch (react-dom.development.js:3514:1) at handleTopLevel (react-dom.development.js:3558:1) at batchedEventUpdates$1 (react-dom.development.js:21871:1) at batchedEventUpdates (react-dom.development.js:795:1) at dispatchEventForLegacyPluginEventSystem (react-dom.development.js:3568:1) at attemptToDispatchEvent (react-dom.development.js:4267:1) at dispatchEvent (react-dom.development.js:4189:1) at unstable_runWithPriority (scheduler.development.js:653:1) at runWithPriority$1 (react-dom.development.js:11039:1) at discreteUpdates$1 (react-dom.development.js:21887:1) at discreteUpdates (react-dom.development.js:806:1) at dispatchDiscreteEvent (react-dom.development.js:4168:1)
根据提供的代码,出现报错的原因是在 `item.searchApi` 中,`searchApi` 并不是一个函数。根据代码逻辑,`searchApi` 是一个使用 `commonService.orgPageList({})` 进行异步请求的 Promise 对象,它的结果会在 `then` 方法中进行处理。
然而,在这段代码中,`searchQuery` 函数中使用了 `item.searchApi()` 来调用这个函数,而实际上 `item.searchApi` 不是一个函数,所以会报错。
要解决这个问题,可以将 `searchQuery` 函数中的 `item.searchApi()` 替换为 `item.searchApi.then()`,并在 `then` 方法中处理结果。
以下是修改后的代码示例:
```jsx
const searchQuery = (value) => {
item.searchApi.then(res => {
const { retData } = res;
retData.map(item => {
return {
key: item.id,
label: item.organName,
value: item.id,
};
});
});
};
// 其他代码...
```
这样修改后,应该就能正确地调用异步请求并处理结果了。
Error: Cannot find module 'fs' at webpackMissingModule (index.js:5:1) at createfilter (index.js:5:1) at changevalue (index.js:41:1) at onClick (index.js:35:1) at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1) at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1) at invokeGuardedCallback (react-dom.development.js:4277:1) at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4291:1) at executeDispatch (react-dom.development.js:9041:1) at processDispatchQueueItemsInOrder (react-dom.development.js:9073:1
这个错误提示与Node.js环境有关,它表示在代码中调用了一个名为“fs”的模块,但是在浏览器环境中是不存在的。因为浏览器不支持访问本地文件系统,所以也不支持该模块。可能的原因是您的代码在浏览器中执行,但是使用了Node.js特有的模块。您需要检查您的代码并将Node.js特有的模块替换为浏览器可以使用的API。如果您需要在浏览器中访问本地文件系统,您可以考虑使用HTML5提供的File API。
阅读全文