Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react onclick remove component

var App = React.createClass({
  render: function() {
    var img = this.state.showImage ? <MyImage /> : '';
    return (
    <div>{img}<RemoveImageButton clickHandler={this.removeImage} /></div>
    );
  },
  
  getInitialState: function() {
      return {
          showImage: true
      };
  },
  
  removeImage: function() {
      this.setState({ showImage: false });
  }
});

var MyImage = React.createClass({
  render: function() {
    return (
      <img id="kitten" src={'http://placekitten.com/g/200/300'} />
    );
  }
});

var RemoveImageButton = React.createClass ({
  render: function() {
    return (
      <button onClick={this.props.clickHandler}>remove image</button>
    )
  }
});

React.render(<App />, document.body);
Comment

PREVIOUS NEXT
Code Example
Javascript :: object delete with id filter javascript 
Javascript :: get ip of user in node js 
Javascript :: radio button in react 
Javascript :: how to sum two var in jquery 
Javascript :: update formgroup value angular 
Javascript :: js code stars 
Javascript :: js unique array 
Javascript :: vuejs scroll to top 
Javascript :: fatal error: ineffective mark-compacts near heap limit allocation failed – javascript heap out of memory 
Javascript :: javascript recursive sum function 
Javascript :: replace string using javascript 
Javascript :: jest testmatch specific folder 
Javascript :: hide and show modal in jquery 
Javascript :: exec js 
Javascript :: how to get the first letter of a string in jquery 
Javascript :: redux saga delay 
Javascript :: object values javascript 
Javascript :: random integer in nodejs 
Javascript :: livewire file upload progress 
Javascript :: js exec find all 
Javascript :: prop type for ref in react js 
Javascript :: express serve home page 
Javascript :: iterate object js 
Javascript :: set headers in express 
Javascript :: javascript json decode 
Javascript :: react json object pretty 
Javascript :: redux persist a non-serializable value was detected in an action in the path register 
Javascript :: hide a div when user clicks outside of it 
Javascript :: mongoose limit 
Javascript :: queryselector data attribute 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =