question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

10reactions
skmaingicommented, Feb 11, 2020

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. 😫

10reactions
JohnDDuncanIIIcommented, Aug 15, 2018

We fixed this in our codebase by changing

return {
    options: options.map(...some stuff)
}

to

return options.map(...some stuff)

in our loadOptions func

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found