Reputation: 69
I have a react app like this
import Modal from 'some-component'
class Blog extends React.Component {
render () {
<Modal title='' content='' onOk='' onClose=''/>
<SomeComponent> </SomeComponent>
}
}
I am trying to use a separate function to render the modal, and call that function inside the render method like this
...
renderModal = () => {}
render() {
// call renderModal here
<SomeComponent> </SomeComponent>
}
but it doesn't work
Upvotes: 1
Views: 66
Reputation: 1143
render () {
return (
<Modal title='' content='' onOk='' onClose=''/>
<SomeComponent> </SomeComponent>
)
}
you should wrap them in a parent element =>
render () {
return (
<>
<Modal title='' content='' onOk='' onClose=''/>
<SomeComponent> </SomeComponent>
</>
)
}
then you can use
renderModal = () => <Modal title='' content='' onOk='' onClose='' />
render () {
return (
<>
{this.renderModal()}
<SomeComponent> </SomeComponent>
</>
)
}
Upvotes: 2
Reputation: 918
renderModal = () => {
return (........your html....);
}
render () {
{this.renderModal()};
}
You can use this code to get what you are asking..
Upvotes: 3