整个上午一直在努力,似乎无法弄清楚这个三元表达有什么问题.没有记录错误,但表达式的第一部分从未进行过评估.有任何想法吗?
<a className="buy-proposals-credits" onClick={userPaywallStatus === PAYWALL_STATUS_WAITING
? () => openModal(PAYWALL_MODAL)
: () => openModal(PROPOSAL_CREDITS_MODAL)}>(Manage proposal credits)</a>
Run Code Online (Sandbox Code Playgroud) 我在下面的代码中实现了 componentShouldUpdate 以尝试提高性能。这个目标已经实现,但现在评论没有呈现。但是,浏览器控制台显示正在接收所有内容。还有一个 div 呈现评论数量,并且也在更新。
class ProposalDetail extends React.Component {
constructor(props) {
super(props);
this.state = {
sortedComments: []
};
}
componentDidUpdate(prevProps) {
if((!prevProps.proposal || Object.keys(prevProps.proposal).length === 0 ) &&
this.props.proposal && Object.keys(this.props.proposal).length > 0 &&
this.props.proposal.status === 4 ){
prevProps.onFetchProposalVoteStatus(prevProps.token);
}
this.handleUpdateOfComments(prevProps, this.props);
}
shouldComponentUpdate(nextProps, nextState) {
console.log('thisProps', this.props.comments)
console.log('nextProps', nextProps.comments)
if (this.props.comments === nextProps.comments) {
return true
}
else {
return false
}
}
componentDidMount() {
this.props.onFetchLikedComments(this.props.token);
}
componentWillUnmount() {
this.props.resetLastSubmittedProposal();
}
handleUpdateOfComments = (currentProps, nextProps) => {
let …Run Code Online (Sandbox Code Playgroud)