[error]: options.reduce is not a function
See original GitHub issue- I am getting
option.reduce is not a function
error while using async with promise .
<------------get
getOptions = (input) => {
console.log("input",input)
let url=`search_back/`
let data={term:input}
return fetch(`http://localhost:8000/backend/search_back/?term=${input}`,{
method:'GET',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: `JWT ${localStorage.getItem('token')}`
}
})
.then((response) => {
return response.json();
}).then((json) => {
console.log("response=",json)
let js=[]
for(let i=0;i<json.length;i++)
{
js.push({
"label":json[i]["label"],
"value":json[i]["value"]
})
}
return { options: js };
}).catch(function(error) {
console.log("error",error);
});
}
<Async
name="form-field-name"
value={this.state.selectedOption}
loadOptions={this.getOptions}
onChange={(value) => {
console.log("value =",value)
this.setState({selectedOption: value});
}}
filterOptions={(options, filter, currentValues) => {
// Do no filtering, just return all options
console.log("options =",options)
return options;
}}
/>
`
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top Results From Across the Web
TypeError: this.reduce is not a function [duplicate]
This is happening because you are using for..in on an array. You shouldn't be doing that. When you added Array.prototype.xintsum , you added ......
Read more >Array.reduce not a function? - Google Groups
@googlegroups.com. To unsubscribe from this group, send email to mongodb-user...@googlegroups.com. For more options, visit this group at ...
Read more >JavaScript: Uncaught TypeError: n is not a function
This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the...
Read more >Array.prototype.reduce() - JavaScript - MDN Web Docs
If initialValue is provided and the array is not empty, then the reduce method will always invoke the callback function starting at index...
Read more >Rows reduce is not a function fast-csv
it will cause this error Uncaught TypeError: options.reduce is not a function. An auto generated warning from react development enviroment whould be more...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is the most complicated select component I’ve faced. First you need array with specific columns then the data has to be returned in a specific way. 😫
We fixed this in our codebase by changing
to
return options.map(...some stuff)
in our
loadOptions
func