logo
Tags down

shadow

React.js TypeError: Invalid attempt to destructure non-iterable instance


By : Brivio Wang
Date : September 14 2020, 11:00 PM
around this issue I make just simple "todo-list" with Hooks. , Correct this
code :
export const todoReducer = (state, action) => {
  switch(action.type){
    case 'ADD_TODO':
      return { todoList: [...state.todoList, action.payload.todo]};
    default:
      return state;
  }
}
export const addTodo = todo => ({
  type: 'ADD_TODO',
  payload: {todo: todo}
})


Share : facebook icon twitter icon

TypeError: Invalid attempt to destructure non-iterable instance


By : user5762555
Date : March 29 2020, 07:55 AM
will help you I faced with the same issue and looking I found that was a typo. you should use types instead of type i.e:
code :
export function showMessage() {
  return {
    types: [MESSAGE_FETCH, MESSAGE_FETCH_SUCCESS, MESSAGE_FETCH_FAIL],
    promise: (client) => client.get('/post')
  }
}

TypeError: Invalid attempt to destructure non-iterable instance while using react-charts


By : user2326227
Date : March 29 2020, 07:55 AM
Any of those help I have solved my problem, I am posting here just in case anyone else also faces a similar issue.
I have maintained a loading state and load the tag only when the data is fetched from API like:
code :
  {this.state.loading ? (
          ""
        ) : (
          <div
            style={{
              width: "600px",
              height: "300px",
              marginTop: "35px",
              marginLeft: "25px"
            }}
          >
            <Chart
              data={this.state.chart_data}
              series={{ type: "bar" }}
              axes={[
                { primary: true, type: "ordinal", position: "bottom" },
                { type: "linear", position: "left", min: 0 }
              ]}
              primaryCursor
              secondaryCursor
              tooltip
            />
          </div>
        )}

Unhandled Rejection (TypeError): Invalid attempt to destructure non-iterable instance


By : Sriram Dorai
Date : March 29 2020, 07:55 AM
wish help you to fix your issue EDIT:
Based off the data structure provided you could modify your code to...
code :
axios
.get('http://world/sports/values')
.then(response => {
    this.setState({
        playerRanks: response.data.map(obj => {
            return obj.customFieldValueName
        })
    })
})
    ...
    response.data.map(({customFieldValueName}) => {
        return customFieldValueName;
    })
    ...
    ...
    response.data.map(({customFieldValueName}) => customFieldValueName)
    ...
axios
.get('http://world/sports/values')
.catch(err=> console.log(err))
.then(({data}) => {                       // Axios always returns an Object, so I can safely 'attempt' to destructure 'data' property 
    if (data && data.length) {            // making sure 'data' does exist, it is an Array and has > 0 elements
      this.setState({
        playerRanks: data.map(obj => {    // Not destructuring here in case obj isn't actually an Object
            if (obj && obj.customFieldValueName) return customFieldValueName;
            return null;
        }).filter(elem=> elem)            // BIG-O notation: This sequence is O(2N), as in iterates over the entire Array first with .map(), then iterates over the entire Array again with .filter() to clear out 'null' values
      })
    }
})
axios
.get('http://world/sports/values')
.catch(err=> console.log(err))
.then(({data}) => {                       // Axios always returns an Object, so I can safely 'attempt' to destructure 'data' property 
    if (data && data.length) {            // making sure 'data' does exist, it is an Array and has > 0 elements
      this.setState({
        playerRanks: data.reduce((acc,obj) => {    // Not destructuring here in case obj isn't actually an Object
            if (!obj || !obj.customFieldValueName) return acc; // If it doesn't meet assertions just return the existing accumulator (don't add another element .ie 'null')
            return [                        
                ...acc,                      // If it conforms to the assertions the return a new accumulator, by first spreading in all existing elements and the adding the new one (customFieldValueName)
                customFieldValueName
            ]
        },[])                      // BIG-O notation: This is O(1N) or O(N), as in it will only iterate over the Array one time and the reduce() function will filter out 'null' values at the same time
      })
    }
})
[1,2].map(element=> {
// element === 1, first iteration,
// element === 2, second iteration
})
[one, two, ...theRest] = [1,2,3,4,5]

// one === 1 and two === 2 and theRest = [3,4,5]
{one, three, ...theRest} = {one: 1, two: 2, three: 3, four: 4, five: 5}

// one === 1 and three === 3 and theRest === {two: 2, four: 4, five: 5}
// notice order doesn't matter here (three vs two), but you need to access valid properties from the object you're deetructuring from
response.data === [ 
   [ 
     { customFieldValueName: 'any value' }, // label
     {}                                     // CustomStep (this could be any value, not necessarily an Object) 
   ],
   [ 
     { customFieldValueName: 'any value' }, // label
     'any value'                            // CustomStep
   ]
]

React JS Error: Invalid attempt to destructure non-iterable instance


By : Derpious
Date : March 29 2020, 07:55 AM
will help you I caused this error a few times because whenever I write a useState hook, which I would do often, I'm used to using an array to destructure like so:

TypeError: Invalid attempt to destructure non-iterable instance React/Jest


By : Joaquin Lugo Zavala
Date : March 29 2020, 07:55 AM
Does that help Had a similar problem where Storybook threw Invalid attempt to destruct non-iterable instance on a component using hooks (useContext).
The solution was to initiate the context with a default value, createContext([{}, function() {}])
Related Posts Related Posts :
  • Get second last message with Discord.Js
  • Is there anyway to return a "no searches found" with this javascript?
  • javascript addEventListener in react js component not working
  • Why does an alert box keep popping up with the word "undefined"
  • Should I use Jquery to click toggle instead of React?
  • Angular I don't call a function with (load)
  • Is there a way of making a javascript loop to repeatedly press a button?
  • How do I create a function that accepts multiple arguments to perform an arithmetic calculation in JavaScript?
  • Cancel Async/Await
  • How to rerender when refs change
  • Is there a more run-time efficient way to iterate through this array? (JavaScript)
  • Is there a more concise way to write this without a bunch of IF statements?
  • Filter Nested JSON based on the Object
  • Sankey-diagram PowerBI custom visual with color nodes and ordering
  • JavaScript anonymous function simulating arithmetic in lambda calculus, result returns `undefined`
  • How to uglify ES6 javascript with Flask?
  • How to fetch data from RESTAPI with react.js
  • Why does RETURN shows different output in javascript
  • How to correctly store an array of RegEx values in a JSON file and retrive it from Javascript?
  • How to solve slow loading page containing database information
  • React unwanted submit on every character inputed
  • Is it bad form to include <span> and <br> within <td> elements?
  • 'Product' s defined but never used in react?
  • "RNCSafeAreaView" was not found in the UIManager
  • Using Regex inside a textarea in Angular template driven form
  • Entering data directly into a table
  • How disable to select minutes in v-time-picker widget?
  • Rebind an event handler that was unbound with .off() method jQuery
  • In Angular 7 how to load CSS of Arabic language (RTL) from English language (LTR)
  • Unable to use a `Symbol` for a `Group` with paper.js
  • Can vuejs be used inside webcomponent?
  • Load "External" CSS (bootstrap) to specific DIV
  • How to make a checkbox show/hide text with onChange event
  • Is it ok to add meta tag in head using jQuery?
  • How to print to screen all array elements stored in local storage
  • React Native: How to pass params to parent component from child component prop
  • jQuery replace span contains comma with single comma
  • JavaScript function to convert unicode pseduo-alphabet to regular characters?
  • How can I pass parameter correctly?
  • How to create and render an app.json file for Heroku
  • Javascript - Is there a clearer way to express "if (a && b || !a && !b)"?
  • Date Validation in Javascript on Chrome
  • Cannot read a an object in Component, React
  • Can I use conditionals to render a grid widget?
  • How to minify index.html file with hundreds of scripts?
  • How to replace a string with another and with a different colour in ReactJS?
  • i need to give two clicks when the keyboard is open -- React native
  • CodeIgniter Update a row of two tables
  • Bootstrap CSS/Javascript For Carousel Only
  • Using Ionic (angular).Unable to access Hardware back button of mobile devices which have buttons inside the display/scre
  • should I use one component for edit and view with ngif or divided them to components?
  • Referential transparency in functional programming
  • Disable serviceWorker when online
  • How to get the coordinates of the pin/marker using ESRI and JavaScript?
  • Longest decrease subsequence subarray in Javascript
  • Update value from database with the hashed content from another column
  • eror 404 in react-routing
  • Youtube video in <object> tag
  • Is there a way to check null or undefined in a series of object of objects in lodash
  • .save() does not change the value of a field , django
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk