score:1
Accepted answer
your this.simplestorageinstance.getbook
is a promise, that means it is executed asynchronously.
to get it's result you either have to use .then
or the new syntax async/await
. with the following function your items
array will be filled with the correct data :
you will have to put the
async
keyword before your parent function name if you choose this solution
for (i = 0; i < accountlength; i++) {
items.push(await this.simplestorageinstance.getbook(searchaddress, i, { from: searchaddress }))
}
an even shorter syntax would imply using your raw array of accounts and map
it instead of using its length :
const items = myaccounts.map(async () => await this.simplestorageinstance.getbook(searchaddress, i, { from: searchaddress }))
Source: stackoverflow.com
Related Query
- How to make an asynchronous return a promise chain within render() with componentDidMount()?
- How do I update a react.js component with a promise return ?
- Fetch GET request with Reactjs - how do i implement a reusable component within my request to render my data?
- With React, how to access the render return value of a child component
- How to mock API calls made within a React component being tested with Jest
- How to render a component onClick with React?
- How to return the user's status within AWS's user pool using Amplify with Javascript?
- How to load child component with props on first render with React Hooks
- How to make MobX update the component when observable is not used in the render method?
- How do we return a Promise from a store.dispatch in Redux - saga so that we can wait for the resolve and then render in SSR?
- How to render only the concerned component with a custom hook and useContext
- How to make svg react component imports from external module working with create-react-app?
- How can I make my React app render Bootstrap tables with crud
- How to make an Accordion component with Reactstrap?
- How to render a React component styled with Emotion in an iframe in Gatsby site?
- ReactJS Router- How to use history push within function component with parameters?
- How to get a resolved promise to my component with Redux Promise?
- How to 1). put a div , 2). render a component without Route inside <Routes> with React Router in v6 React?
- How to make my component re render after updating props from selector in react and redux-saga?
- How to make a react component with Async data re-usable in Redux flow?
- How to write to apollo cache from within React component with out losing context of "this"
- How to render the same component repeatedly with the same prop?
- How to make a functional React component with generic type?
- How to use ternary operator within the jsx of a react component along with typescript?
- reactjs - How to render a component which render return a component?
- How to render a loading component with the useEffect hook?
- How to mock properly with Jest a React component using render props
- How do I make a higher order React component with Typescript?
- Enzyme & React router: How to shallow render a component with useHistory
- How to handle asynchronous fetch from Database with Gatsby or React functional component
More Query from same tag
- Is there a way to force eject a react app?
- React useEffect and return render
- How React search (filter) all field in array?
- Dynamic class names in SASS
- How to render an object of arrays with useEffect
- Route is giving 404 with React
- Unicode JSON in Laravel blade for use in React, generating a JSON.parse problem
- React typescript onChange is showing error when I try to add it to material UI switch
- React: how can you share the state between views using react-router?
- Is there a way to share state between all instances of a React component?
- Javascript date showing a different time by using New Date
- How to filter Dynamic nested array of JSON objects based on text match with both upper and lower case
- unexpected token reactjs app on codesandbox
- Differences between defining shallow in describe block and in every test block?
- Functional component to class component Error: Cannot read property 'id' of undefined
- React getting previous version of state when calling a function in useContext
- postMessage from navigator in componentDidMount returns undefined
- Passing refs for carousel into typescript using React and Ant design?
- React: why my links that are inside React components are not working as used to work in pure HTML page?
- can we pass props to another react router page without context and redux?
- Initializing materialize in react apps
- React useState conditional initial value
- Typescript taking in Javascript component; How to solve errors
- Image is sticking to bottom of the div in my React Component
- Create React App Blank Page when including on existing site
- How to add 4 elements (objects) in array to localstorage, react
- Pass argument onClick to props.function() executed via refs
- Split a string with HTML <br> tag into multiline string
- How do I prevent Chartjs tooltip callback returning multiple instances of the same value?
- How can I access the local storage on page reload in redux store?