2

I am new to React.js and one question I have is - Is it necessary to unmount a React Modal view before re-rendering it.

I am trying to call a react modal view as below. The modal shows up only the first time. But if the modal is unmounted before this render function is called, the Modal shows up.

render: function(options) {
    React.renderComponent(<ModalView id="ModalView" 
                         model={this.model}/>,$("#"+this.viewId)[0]);
},

Thanks.

0

2 Answers 2

2

You should only call React.renderComponent() on the root component. To render a child component just return it in the render method.

render: function() {
        return <ModalView id="ModalView " model={this.model}/>;
}

And to answer your question, no, you shouldn't need to explicitly unmount anything. To trigger a render you either setState, setProps or forceUpdate.

Sign up to request clarification or add additional context in comments.

Comments

0

Are you using bootstrap modal? I have the same issue. Once rendered the componentDidMount would not be called. Hence modal would not be shown. I defined a onClose props to unmount the component on close. If there is a better way i would be interested.

1 Comment

componentDidMount is called on initial render. componentDidUpdate is called on subsequest renders.

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.