1

I have a list of items (ProjectActivityList), for each item there is the Edit button. Clicking on it opens modal to edit the item. The modal accepts an ID.

var ProjectActivities = React.createClass({

    onEditItem: function(id){
        // I want to pass the ID to modal and open it
    },

    render: function(){
        return (
           <div>
               <ProjectActivityList items={this.state.activities} onEdit={this.onEditItem}/>
               <Modal />
           </div>
        )    
    }    
});

How I can open the modal passing to it the ID (in onEditItem)?

1
  • 2
    this.setState({ currentId: id }) ? Commented Aug 7, 2016 at 17:01

1 Answer 1

2

You want to pass it as a prop and set the state of the current element. By setting the state, a re-render will be performed (if necessary, which it is in this case) and so the Modal will receive the new id.

var ProjectActivities = React.createClass({

    onEditItem: function(id){
        // I want to pass the ID to modal and open it
        this.setState({editingId: id});
    },

    render: function(){
        return (
           <div>
               <ProjectActivityList items={this.state.activities} onEdit={this.onEditItem}/>
               <Modal id={this.state.editingId} />
           </div>
        )    
    }    
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.