저는 React Bootstrap Table
입니다. 테이블의 각 페이지에는 20 개의 레코드가 있습니다. 각 행에서, I는React Bootstrap 테이블에는 모달을 만들 때 각 행에 버튼이 있지만 한 버튼은 모달의 렌더링을 여러 번 호출합니다
function attachFormatter(cell, row){
return (
<AttachmentManager />
);
}
<TableHeaderColumn key={uuid.v4()}
dataField={column.dataField}
dataFormat={attachFormatter}
hidden={hide}>
{column.label}
</TableHeaderColumn>
그럼 I이 페이지 20 개 버튼이 있고, 각 행은 하나 개의 버튼이 다음 줄을 사용하여 버튼을 추가했다. 단추 중 하나를 클릭하면 모달을 열려고했습니다. 그러나 하나의 버튼을 클릭하면 openModal()
이 예상대로 실행되지만 의 render()
기능은 20 번 실행됩니다. 어떻게 해결할 수 있을까요?
export default class AttachmentManager extends React.Component {
constructor (props) {
super(props);
this.state = {showModal: false};
}
openModal() {
alert('test');
}
render() {
return (
<button onClick={this.openModal.bind(this)} className="btn btn-default">Add Projects
<AttachmentModal show={this.state.showModal}/>
</button>
);
}
}
그리고 다음은 내 모달
import React from 'react';
import SimpleModal from '../common/SimpleModal';
export default class AttachmentModal extends React.Component {
constructor (props) {
super(props);
}
render() {
return (
<SimpleModal showModal={this.props.show}
onToggleModal={this.props.onHide}
title={this.props.title}
onCancelClick={this.props.onHide}
onPrimaryButtonClick={this.props.onPrimaryButtonClick}
cancelText="Cancel"
primaryButtonText={this.props.primaryButtonText}
loading={this.props.loading}
backdrop='static'
bsStyle={this.props.bsStyle}>
{this.props.children}
</SimpleModal>
);
}
}
여전히 동일합니다. 하나의 버튼을 클릭하면'render()'가 20 번 호출됩니다. –
질문에 'AttachmentModal'코드를 추가 할 수 있습니까? – palsrealm
수정 된 코드 참조. 렌더링을 버튼 만 만들 수 있도록'AttachmentManager'에서' '줄을 삭제했지만 렌더는 여전히 여러 번 실행됩니다. –