私が反応し-Reduxのconnect
を使用して、このコンポーネントがあります。コンテナコンポーネントに接続し使用してステートレスなコンポーネントを変換する - 最適化
let Vepo = (props) => (
<Container >
<Header style={styles.header}>
<Left>
<Button transparent>
</Button>
</Left>
<Body>
<Title style={styles.title}>Search</Title>
</Body>
<Right>
</Right>
</Header>
<Container style={styles.container}>
<ScrollView >
<Keywords />
<Categories />
</ScrollView>
</Container>
</Container>
)
Vepo = connect(
null,
null
)(Vepo)
export default Vepo
をそして私はちょうど簡単にライフサイクルメソッドを使用するためにはconnect
ずにコンテナコンポーネントにそれを変換しています:
class Vepo extends Component {
componentDidMount() {
const { store } = this.context
this.unsubscribe = store.subscribe(() => {
this.forceUpdate()
console.log(store)
})
console.log(store)
}
componentWillUnmount() {
this.unsubscribe()
}
render() {
return(
<Container >
<Header style={styles.header}>
<Left>
<Button transparent>
</Button>
</Left>
<Body>
<Title style={styles.title}>Search</Title>
</Body>
<Right>
</Right>
</Header>
<Container style={styles.container}>
<ScrollView >
<Keywords />
<Categories />
</ScrollView>
</Container>
</Container>
)}
}
Vepo.contextTypes = {
store: React.PropTypes.object
}
export default Vepo
しかし、私はちょうどその答えから見てきましたforceUpdate()
は不要なハックです。
performantコンポーネントを使用するには、componentDidMount
とcomponentWillUnmount
で何をする必要がありますか?購読は必要ですか?もし私がthis.forceUpdate()
だけを削除すれば、それはパフォーマンスの高いコンポーネントになりますか?
おかげで、私は私が必要と述べたライフサイクルの方法はありますか? – BeniaminoBaggins
答えを更新して追加しました。私はそれらが必要でないので削除しました:)。コードのように、すべてのストアを1つのコンポーネントに追加するのは良い考えではありません。 –