RadioButton click TypeError: Cannot read property 'setState' of undefined

RadioButton click TypeError: Cannot read property 'setState' of undefined

Content Index :

RadioButton click TypeError: Cannot read property 'setState' of undefined
Tag : reactjs , By : jan
Date : January 11 2021, 03:32 PM

wish helps you You have two options here. Either use arrow function or bind your function to this inside your constructor.
Why is it not working?
onRadioChange = (e) => {
  this.setState({ name: 'newName' });
class MyApp extends React.Component {
   constructor(props) {
      this.onRadioChange = this.onRadioChange.bind(this);

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

TypeError: cannot read property setState of undefined

Tag : reactjs , By : Alex
Date : March 29 2020, 07:55 AM
hope this fix your issue Its a context issue, your mistake is that you didn't bind all the way down to the anonymous function. What you probably want to do is use arrow functions, try this:
componentDidMount() {
    .then(data => this.setState({dos:data}););
componentDidMount() {
      .then(function(data) {

TypeError: Cannot read property 'setState' of undefined

Tag : javascript , By : Rob
Date : March 29 2020, 07:55 AM
like below fixes the issue Bind the callback function also so that this inside the callback points to the context of the React Component and not the callback function
getPosts = () =>  {
        type: 'get',
        url: urlname,
        success: (data) => {
            this.setState( { posts: data } )
getPosts = () =>  {
        type: 'get',
        url: urlname,
        success: function(data) {
            this.setState({ posts: data })

TypeError: Cannot read property 'setState' of undefined/XML

Tag : reactjs , By : cnemelka
Date : March 29 2020, 07:55 AM
it should still fix some issue You're mixing and matching function()s that don't capture this and arrow (=>) functions which do.
Simply use arrow functions everywhere and the this (that's your React component) will be properly captured:
  .then(response => {
    parseString(response.data, (err, result) => {
      if (err) {
        throw err;
      } else {
          odm: result.data,
          loading: false,
  .catch(error => {
// promisified version of `parseString`:
const parseStringP = data =>
  new Promise((resolve, reject) =>
    parseString(response.data, (err, result) => {
      if (err) return reject(err);

// ...

try {
  const response = await axios.get(session_url);
  const result = await parseStringP(response.data);

    odm: result.data,
    loading: false,
} catch (error) {

Rejection (TypeError): Cannot read property 'setState' of undefined, Uncaught (in promise) TypeError: Cannot read proper

Tag : node.js , By : August
Date : March 29 2020, 07:55 AM
Does that help To solve the setState issue, you need to be aware that the async.auto({}) is a promise.
The final error function need to be deleted this code:
function (err, results)
    console.log('error: ', err)
    this.setState({active: result.optionsFill})

react setstate TypeError: Cannot read property 'setState' of undefined

Tag : reactjs , By : Hitesh Prajapati
Date : March 29 2020, 07:55 AM
around this issue , Either bind this to your function in the constructor

    this.handleChange = this.handleChange.bind(this);

<input type="checkbox" onChange={(e)=>this.handleChange(e)} />
Related Posts Related QUESTIONS :
  • How do I write a React Spring to change margin?
  • React tab doesn't appear in chrome developer tools
  • How to redirect to another component by setting up props from this component in react.js
  • Centre Buttons horizontally and vertically
  • Customize Reactive Search DateRange
  • Anyone know why my Component Keeps Remounting?
  • How to get the latest state value after using setState?
  • How to return value in component react typescript
  • How should useDispatch be used to enforce type checking?
  • Property 'title' does not exist on type 'IntrinsicAttributes & IProps'
  • What are the disadvantages of client-only routes?
  • Dropping files or opening files from the file selector dialog box causes the React component to unmount
  • How to check if a component has been clicked after an onblur event in React
  • What should be considered as component in React
  • Updating Parents state from Child without triggering a rerender of Child in React
  • Select component is ignoring parent onClick event
  • How to add Condition inside render method in reactjs
  • How to fix form that will not allow text to be entered?
  • Cannot read property 'name' of undefined on React with my props
  • Material UI tooltip doesn't display on custom component, despite spreading props to that component
  • Unexpected output but expected view when using hooks React for toggle
  • Determine if two objects have an identical structure with Jest
  • Material ui - snackbox aria label not being read
  • Why is useState hook calling initialising value code twice?
  • React - override state by exists object properties
  • how to stop re-rendering of list items in context consumer when state changes
  • how to pass props one page to another page via react router?
  • How to display react numerical props only if they pass from the container?
  • Input in another component, error with target
  • What is the difference between props and children in Gatsby?
  • Validating conditional pairs of props with Typescript
  • React-Dropzone how convert each file to base64
  • How to change the return of a function to int?
  • Import only grid system from bootstrap to react
  • TypeScript Type for function arguments not erroring?
  • Unexpected user of comma operator no-sequences
  • React Native onChangeText like onChange in ReactJS
  • How to dynamically render an element on clicking a button
  • Cannot import components from react-bootstrap
  • How to prevent Office UI Fabric React DatePicker flyout from stealing focus when allowTextInput is true?
  • How delete item from redux state?
  • Uncaught TypeError: map is not a function In Reactjs with Firebase
  • Alternative to componentWillReceiveProps for my particular use case
  • Pokemon, API call Variable doesn't save
  • Rendered more hooks than during the previous render. when posting form data with React Hooks
  • How can I envoke <Link to=''> route transition from a custom function?
  • How to change certain div color base on number
  • Hide Navbar on some routes (React Router v5)
  • is it safe to ignore react's warning about calling the useState hook conditionally when only the parameter is conditiona
  • How to pass a function as a prop to React function component?
  • Creating a function that replace a letter with a line break
  • How to add and remove property from Redux state
  • Can I, (and should I), make assertions about what HTML elements a component renders using Enzyme's shallow()?
  • Testing function calls in Jest after button click (mocking fetch calls)
  • How can I show a card shadow on all sides?
  • Jest - Map through an Array of Items and test their Values
  • Run Effect hook only when both dependencies change
  • What is the difference between .ts and .tsx extensions. Both are used as extensions for typescript files in react. So wh
  • Font size of tooltip in speeddialaction of React's Material UI
  • Module Not Found - Webpack Dev Server
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com