Posts

Showing posts with the label setstate

React Native setState not a function

React Native setState not a function Can someone explain me why this.setState is not a function ? I do not see why my code has an error import React from 'react'; import axios from 'axios' import { StyleSheet, Text, View , Image} from 'react-native'; export default class App extends React.Component { constructor(){ super(); this.state = {res: } } componentDidMount() { axios.get('https://api.github.com/repos/torvalds/linux/commits') .then(function (response) { this.setState({res: response}); }).catch(function (error) { console.log(error); }); } } Thank you use arrow function to wrap this.setState({res: response}); that bring this inside arrow function – Pramendra Gupta Jun 29 at 9:51 this.setState({...