Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

cannot setState in event handler

class DropDownItem extends Component {
  constructor(props) {
    super(props)
    this.state = {
      selectedItem : "" 
    }
    this.updateItem = this.updateItem.bind(this)
  }

  updateItem (item, callback) {
    this.setState({selectedItem : item}, callback)
  }

  render(){
    return (
      <div>
        <DropdownItem onClick={() => {
            this.updateItem(this.props.product, ()=>{
                console.log("item",this.state.selectedItem)
            })
          }}  
        >{this.props.product}</DropdownItem>
        <DropdownItem divider/>
      </div>
    )
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: routing/switches 
Javascript :: React Native - iOS Release build crashing 
Javascript :: js get first elements of array 
Javascript :: parseint javascript online 
Javascript :: json whitespace code 
Javascript :: arithmetic 
Javascript :: registration page validation in react 
Javascript :: Javascript twoSum algorithm: Given an array of integers, return indices of the two numbers such that they add up to a specific target 
Javascript :: python code to javascript converter 
Javascript :: how to skip the else statment in react tertiary 
Javascript :: send a message in the first channel discord.js 
Javascript :: prevent the Confirm Form Resubmission dialog | window.history.back() confirm form resubmission 
Javascript :: stringToCapital.js 
Javascript :: vue append component to div 
Javascript :: wait untill 2 
Javascript :: how to get on hnage input before clicking off 
Javascript :: base64-XMLHttpRequest 
Javascript :: discord.js profile picture 
Javascript :: react get variable from child component 
Javascript :: javascript asynchronous function list 
Javascript :: timezone using javascript 
Javascript :: javascript oop 
Javascript :: js template literals 
Javascript :: subarray javascript 
Javascript :: ajax post request 
Javascript :: javascript prefill form 
Javascript :: findPotentialLikes javascript 
Javascript :: javascript Adding Element to the Inner Array 
Javascript :: convert dom object to string 
Javascript :: npx cypress --spec run selected tests 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =