score:2
Accepted answer
the issue is with this
.
instead of this,
saiindexeddb(response.data).then(function(result){
this.setstate({
loadingmedications: false
});
})
you need to use arrow function which auto binds this
,
saiindexeddb(response.data).then((result) => {
this.setstate({
loadingmedications: false
});
})
score:0
another solution is assigning this
to a variable and use that variable in callback
const self = this;
saiindexeddb(response.data).then(function(result){
// replace $this with $self
self.setstate({
loadingmedications: false
});
})
.catch(function(error){
console.log('error', error);
});
Source: stackoverflow.com
Related Query
- React app is throwing error Cannot read property 'setState' of undefined in nested promise
- an error whilst working with react app - Cannot read property 'photo' of undefined
- Error Cannot read property 'left' of undefined in React Semantic UI Popup with Styled Component
- Cannot read property 'push' of undefined - React error
- import Excel from "exceljs" throwing error on browser TypeError: Cannot read property 'prototype' of undefined
- react component error Cannot read property of undefined
- TypeError: Cannot read property 'url' of undefined / React App crashing
- React fullcalendar error cannot read property 'seg' of undefined
- TypeError: Cannot read property 'name' of undefined react error
- Create React App production build runtime error: Cannot read property 'call' of undefined
- react setstate TypeError: Cannot read property 'setState' of undefined
- React router error Cannot read property 'forEach' of undefined
- ReactJs displays error Cannot read property setState of undefined with Axios form submission
- Error when trying to use the result of a function, typeError: Cannot read property 'map' of undefined in React
- create react app error: TypeError: Cannot read property 'split' of undefined
- Error adding Google Maps with react - TypeError: Cannot read property 'maps' of undefined
- Can't resolve the error Cannot read property 'map' of undefined in react js
- Cannot read property 'map' of undefined in react datatable error
- Cannot read property setState of undefined while trying to set the state in my React project
- Cannot read property formatMessage of undefined error message from react code
- React Redux error Unhandled Rejection (TypeError): Cannot read property 'data' of undefined
- Cannot read property of setState of undefined REACT
- I get the error : - Unhandled Rejection (TypeError): Cannot read property 'id' of undefined in React Application
- React file throws error Cannot read property 'style' of undefined only when I refresh the page
- Changing the react-leaflet layer url by mutating react state throws error -> TypeError: Cannot read property 'call' of undefined
- TypeError: Cannot read property 'params' of undefined at App React Router
- Error in React CRUD app : TypeError: Cannot destructure property 'id' of 'this.props.event' as it is undefined
- TypeError: Cannot read property 'then' of undefined, React app error when trying to save a playlist
- React Cannot read property setState of undefined in .then() even using arrow function
- RelayObservable: Unhandled Error TypeError: Cannot read property 'subscribe' of undefined in React and Relay
More Query from same tag
- searchkit: RefinementListFilter can't access certain data in json
- Simply return a value from another component
- Cant align Typography under App Bar Material UI
- Sorting an array which contains string object in react
- How to find the given image source (url) is in svg format?
- Cannot fetch data after refreshing the page in Next.js
- How do I show a hand symbol (cursor pointer) when the mouse hovers on date field in Material UI?
- add new item CRUD react
- dont want return children on get list mongodb
- ReactJS Function Component: accordion, allow for multiple selected open with useState
- React State not updating on key event
- Why does Cypress not recognise the testid of a react-datepicker element?
- React: How do I use my consumer inside ComponentDidMount to change state?
- How to format dates in JavaScript specifically?
- Why do I need to use Context or a Provider with MobX?
- How to fix issue linking with Provider my store and passing data to components in my Redux-React app?
- In ReactJS is there a way to filter rendered results that are being iterated over?
- Polymorphic Typescript Component for Social Icon Component
- Formatting JSON data for Tree Graph
- How to get cropped image after crop as a form data in react
- How to add redux-persist to typescript project?
- How to update react state with dropdown menu selection? I am using semantic UI for the dropdown
- Formik reset errors
- npm not allowing me to update React
- React hook useState not updating onclick
- React npm start issue
- applying filter state with react
- React with Google Apps Script
- changing style of paragraph in dropzone-material-ui
- how can I toggle a boolean parameter in javascript?