私は常にreact-redux connect
を使用して小道具を構成しましたが、ライフサイクルメソッドを使用するにはComponent
という反応を使用する必要があります。私は店からつかんでいる私の小道具が静的であるように見えており、店の更新として更新していないことに気付いています。reactxがreduxストアで更新しない
コード:
class AlertModal extends Component {
title
isOpen
message
componentDidMount() {
const { store } = this.context
const state = store.getState()
console.log('state', state)
console.log('store', store)
this.unsubscribe = store.subscribe(() => this.forceUpdate())
this.title = state.get('alertModal').get('alertModalTitle')
this.isOpen = state.get('alertModal').get('isAlertModalOpen')
this.message = state.get('alertModal').get('alertModalMessage')
this.forceUpdate()
}
componentWillUnmount() {
this.unsubscribe()
}
updateAlertModalMessage(message) {
this.context.store.dispatch(updateAlertModalMessage(message))
}
updateAlertModalTitle(title) {
this.context.store.dispatch(updateAlertModalTitle(title))
}
updateAlertModalIsOpen(isOpen) {
this.context.store.dispatch(updateAlertModalIsOpen(isOpen))
}
render() {
console.log('AlertModal rendered')
console.log('AlertModal open', this.isOpen) <======= stays true when in store it is false
return (
<View
私は
title
を設定するにはどうすればよい
、isOpen
、およびmessage
ので、彼らはすべての回でストア値を反映?
this.forceUpdate()の必要性は何ですか? – Codesingh
接続を使用してレビュックスストアにコンポーネントを接続するだけです。次に、mapStateToPropsを使用して更新された小道具を取得します。 –
@Codesinghビューの高さを取得するために 'onLayout'を使うコードのさらに下のビューがあります。次に、高さを使用してコンテンツのスタイルを設定します。そのため、 'forceUpdate'をマウントした後に呼び出す必要があります。なぜなら、最初のレンダーには高さがないからです。 – BeniaminoBaggins